If you can install third-party libraries, then httplib2 will be easier to use and a more powerful alternative to urllib.request :
import httplib2 h = httplib2.Http("/path/to/cache-directory") h.add_credentials(username, password) response, content = h.request(url) assert response.status == 200
source share