title: Google API + proxy + httplib2
body: <p>I'm currently running a script to pull data from Google Analytics with  <a href="/questions/tagged/googleapiclient" class="post-tag" title="show questions tagged &#39;googleapiclient&#39;" rel="tag">googleapiclient</a> Python package (that is based on <a href="/questions/tagged/httplib2" class="post-tag" title="show questions tagged &#39;httplib2&#39;" rel="tag">httplib2</a> client object)</p>
  
  <p><strong>--> My script works perfectly without any proxy.</strong></p>
  
  <p>But I have to put it behind my corporate proxy, so I need to adapt my <code>httplib2.Http()</code> object to embed proxy information. </p>
  
  <p>Following <code>httplib2</code> doc <a href="https://github.com/jcgregorio/httplib2/blob/master/python3/httplib2test.py" rel="nofollow noreferrer">1</a> I tried: </p>
  
  <pre><code>pi = httplib2.proxy_info_from_url('http://user:pwd@someproxy:80')
  httplib2.Http(proxy_info=pi).request("http://www.google.com")
  </code></pre>
  
  <p>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)</p>
  
  <p>I also downloaded socks in <code>PySocks</code> package (v1.5.6) and tried to "wrapmodule" httplib2 as described in here:
  <a href="https://github.com/jcgregorio/httplib2/issues/205" rel="nofollow noreferrer">https://github.com/jcgregorio/httplib2/issues/205</a></p>
  
  <pre><code>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")
  </code></pre>
  
  <p>But I get an IndexError: (tuple index out of range)</p>
  
  <p>In the meantime,
  When I use the <a href="/questions/tagged/requests" class="post-tag" title="show questions tagged &#39;requests&#39;" rel="tag">requests</a> package, <strong>this simple code works perfectly</strong>:</p>
  
  <pre><code>os.environ["HTTP_PROXY"] = "http://user:pwd@someproxy:80"
  req = requests.get("http://www.google.com")
  </code></pre>
  
  <p>The problem is that need to fit with <code>googleapiclient</code> requirements and provide a <code>htpplib2.Http()</code> client object.</p>