barrybrianbarrios / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

Proxy authentication setting #29

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Get behind a proxy server that needs authentication
2. Try to get any data from twitter.com 

What is the expected output? What do you see instead?
Timeline or statuses or whatever we request

What version of the product are you using? On what operating system?
python-twitter 0.5, Python 2.5.2, Ubuntu 8.04

Please provide any additional information below.

I tried setting the proxy information on twitter.urllib2, but that doesn't
seem to work. How can I set my proxy settings to the library? Thanks for
the help

Original issue reported on code.google.com by m.s.saha...@gmail.com on 26 Oct 2008 at 12:56

GoogleCodeExporter commented 9 years ago
Accepting.  This will be addressed post-0.6 with the HTTP layer rewrite.

Original comment by dclinton on 21 Feb 2009 at 5:29

GoogleCodeExporter commented 9 years ago
I have python-twitter 0.6;  how does one setup using an HTTP proxy and 
authentication?

Original comment by adamtaun...@gmail.com on 8 Dec 2009 at 2:03

GoogleCodeExporter commented 9 years ago

Original comment by bear42 on 16 May 2010 at 11:40

GoogleCodeExporter commented 9 years ago
Change _GetOpener function in twitter.py with :

  def _GetOpener(self, url, username=None, password=None):
    proxies = {'http': 'http://USERNAME:PASSWORD@PROXY_SERVER:80/'}
    proxyHandler = self._urllib.ProxyHandler(proxies)
    if username and password:
      self._AddAuthorizationHeader(username, password)
      handler = self._urllib.HTTPBasicAuthHandler()
      (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
      handler.add_password(Api._API_REALM, netloc, username, password)
      opener = self._urllib.build_opener(handler, proxyHandler)
    else:
      opener = self._urllib.build_opener(proxyHandler)
    opener.addheaders = self._request_headers.items()
    return opener

for non http proxies, replace http with respective proxy

Original comment by hasanatk...@gmail.com on 28 Jun 2010 at 11:07

GoogleCodeExporter commented 9 years ago
Here is the final twitter.py, look into documentation (of Api class) to see how 
to use it with proxy.

Original comment by hasanatk...@gmail.com on 28 Jun 2010 at 8:13

Attachments: