0

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.*

Matt
  • 501
  • 3
  • 13
  • In my python 2 implementations I just have used environment variables: set https_proxy=https://someuser:somepwd@10.1.1.1:8080. Does that work? – Peter Dec 07 '16 at 01:33
  • Unfortunately not. Thanks for looking into this so late after it was posed – Matt Dec 07 '16 at 02:30

3 Answers3

2

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()) 
Antoine Tissier
  • 621
  • 5
  • 13
  • Amazing - thankyou. I simply changed it to import httplib2shim as httplib2 and everything worked right off the bat – Matt Aug 23 '17 at 04:12
0

I, actually, found these related issues which still remain unresolved:

You may want to also check their discussions regarding them and hope you find some helpful ideas.

Teyam
  • 7,686
  • 3
  • 15
  • 22
0

I appreciate everybody's help - unfortunately neither google (company or their results) had any solutions and as end of year approaches I don't have time to run all tasks through my mobile.

If anybody is interested in the "fix": I simply moved back to python2.7 and replaced a few {**foo} type statements with their 2.x equivalent.

Cheers

Matt
  • 501
  • 3
  • 13