adameubanks / python-twitter

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

Proxy support missing #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Actual implementation doesn't allow to explicitly specify a proxy (you can
override _GetOpener() so you can chain a ProxyHandler over the
HTTPBasicAuthHandler, but that's a kinda hack).

It's a common need to pass through a proxy, so there should be a (easy) way
to specify proxy informations.

Original issue reported on code.google.com by giulian...@gmail.com on 30 Sep 2008 at 5:37

GoogleCodeExporter commented 9 years ago
I think we need a more pluggable HTTP layer in general.  There are a number of 
things
that the user can't control right now that makes it difficult.

Original comment by dclinton on 26 Oct 2008 at 4:22

GoogleCodeExporter commented 9 years ago
This will be addressed post 0.6 when we overhaul the HTTP layer to support 
OAuth.

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

GoogleCodeExporter commented 9 years ago
I add proxy support with authentification for python-twitter 0.5

Here is the code of Opener:

  def _GetOpener(self, url, username=None, password=None, proxy_username=None,
proxy_password=None, proxy_host=None, proxy_port=None):
    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)

      if proxy_username and proxy_password and proxy_host and proxy_port:
        proxyinfo = {
          'user' : proxy_username,
          'pass' : proxy_password,
          'host' : proxy_host,
          'port' : proxy_port
        }

        proxyhandler = self._urllib.ProxyHandler({"http" : \
          "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxyinfo})
        opener = self._urllib.build_opener(proxyhandler, handler)
      else:
        opener = self._urllib.build_opener(handler)

      self._urllib.install_opener(opener)
    else:
      opener = self._urllib.build_opener()
      self._urllib.install_opener(opener)
    opener.addheaders = self._request_headers.items()
    return opener

Unfortunately, this code doesnt allow use proxy without authorization in 
Twitter.

I attach modified twitter.py (0.5) with proxy support.

Original comment by schmoo...@gmail.com on 30 Jul 2009 at 5:22

Attachments:

GoogleCodeExporter commented 9 years ago
to be applied to dev branch

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

GoogleCodeExporter commented 9 years ago
The use of urllib2 has changed considerably since 0.5/0.6. I created a clone of 
0.8.1 that supports proxy authentication (and a socket timeout).

http://code.google.com/r/michaelscovetta-auth-proxy-support/source/browse

Original comment by michael....@gmail.com on 24 Jan 2011 at 7:07

GoogleCodeExporter commented 9 years ago
Dear Michael,

Thank you very much Mr. Michael for your code which handles the issues of proxy.

regards
avijit

Original comment by avijit0...@gmail.com on 7 Nov 2013 at 6:17