Google API + proxy + httplib2

I am currently running a script to retrieve data from Google Analytics with the Phyton Package (based on httplib2

→ My script works fine without a 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 that did not work. I always get a Time out error with or without proxy information (therefore, the proxy_info parameter is not taken into account in the parameter)

I also loaded the socks into the package (v1.5.6) and tried to "wrap the module" httplib2, as described 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 IndexError: (the tuple index is out of range)

Meanwhile, when I use requests , this simple code works fine :

os.environ["HTTP_PROXY"] = "http://user:pwd@someproxy:80"
req = requests.get("http://www.google.com")

The problem is that you need to meet the requirements of googleapiclient and provide the client object htpplib2.Http ().

+4
source share
2 answers

- Python 2, httplib2. . .

+1

Python2, , httplib2shim

: https://dinatam.com/fr/python-3-google-api-proxy/

:

from httplib2 import Http
http_auth = credentials.authorize(Http())

:

import httplib2shim
http_auth = credentials.authorize(httplib2shim.Http())
0

All Articles