I'm currently running a script to pull data from Google Analytics with googleapiclient Python package (that is based on httplib2 client object)
--> My script works perfectly without any proxy.
But I have to put it behind my corporate proxy, so I need to adapt my httplib2.Http()
object to embed proxy information.
Following httplib2
doc 1 I tried:
pi = httplib2.proxy_info_from_url('http://user:pwd@someproxy:80')
httplib2.Http(proxy_info=pi).request("http://www.google.com")
But it did not work. I always get a Time out error, with or without the proxy info (so proxy_info in parameter is not taken into account)
I also downloaded socks in PySocks
package (v1.5.6) and tried to "wrapmodule" httplib2 as described in here:
https://github.com/jcgregorio/httplib2/issues/205
socks.setdefaultproxy(socks.PROXY_TYPE_HTTP, "proxyna", port=80, username='p.tisserand', password='Telematics12')
socks.wrapmodule(httplib2)
h = httplib2.Http()
h.request("http://google.com")
But I get an IndexError: (tuple index out of range)
In the meantime, When I use the requests package, this simple code works perfectly:
os.environ["HTTP_PROXY"] = "http://user:pwd@someproxy:80"
req = requests.get("http://www.google.com")
The problem is that need to fit with googleapiclient
requirements and provide a htpplib2.Http()
client object.
I decided to recode my web app in Python 2, still using the httplib2 package. Proxy info are now taken into account. It now works.