Google API + proxy + httplib2 -
i'm running script pull data google analytics googleapiclient phyton package (that based on httplib2 client object)
--> script works without proxy.
but have put behind corporate proxy, need adapt httplib2.http() object embed proxy information.
following httplib2 doc1 tried:
pi = httplib2.proxy_info_from_url('http://user:pwd@someproxy:80') httplib2.http(proxy_info=pi).request("http://www.google.com")
but did not work. time out error, or without proxy info (so proxy_info in parameter not taken account)
i downloaded socks in pysocks package (v1.5.6) , tried "wrapmodule" httplib2 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 indexerror: (tuple index out of range)
in meantime, when use 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 need fit googleapiclient requirements , provide htpplib2.http() client object.
i decided recode web app in python 2, still using httplib2 package. proxy info taken account. works.
Comments
Post a Comment