Search code examples
python-3.5google-admin-sdkgoogle-directory-apihttplib2

Can't connect to google directory-api using proxy with httplib


I have my scripts ready to manage users in google however I can't find anyway to use a proxy with httplib2, as such I am constantly switching to mobile to avoid doing tasks by hand.

For refrence all code comes from the quickstart : https://developers.google.com/admin-sdk/directory/v1/quickstart/python

Simplified to:

credentials = gi.get_credentials()
http = credentials.authorize(httplib2.Http())
service = gi.discovery.build('admin', 'directory_v1', http=http)
print('Starting user OU management')

I have found this but it doesn't seem to work for HTTP proxy

http = credentials.authorize(httplib2.Http(httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, 'proxy.example.com', 8080, proxy_user = 'username', proxy_pass = 'password') ))

Proxy information:

  • Host: wpad
  • port: 8080
  • Same proxy for both HTTP and HTTPS traffic
  • No auth

EDIT: found this https://github.com/jcgregorio/httplib2/wiki/Examples-Python3

Proxy support is unavailable until the third-party socks module is ported to Python 3.

So are there any other http libraries that I can use??

Thanks

EDIT 2: Spoke to google and apparently 3.5 isn't supported at all, however this doesn't solve my httplib2 problem with python 3.*


Solution

  • I think you should try using httplib2shim rather than httplib2

    You can have a look at this tutorial on my blog : https://dinatam.com/fr/python-3-google-api-proxy/

    In simple words, just replace this kind of code :

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

    by this one :

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