ajgoune / python-twitter

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

Patch: Allow additional handlers for opener - Proxy Support #205

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
We were having some issues using the library from behind a proxy. This patch 
will allow additional handlers to be attached to opener.

Below is an example implementation we used.

class TwitterApiExtension(twitter.Api):
    def __init__(self,
               consumer_key=None,
               consumer_secret=None,
               access_token_key=None,
               access_token_secret=None,
               input_encoding=None,
               request_headers=None,
               cache=twitter.DEFAULT_CACHE,
               shortner=None,
               base_url=None,
               use_gzip_compression=False,
               debugHTTP=False):

        twitter.Api.__init__(self,
               consumer_key,
               consumer_secret,
               access_token_key,
               access_token_secret,
               input_encoding,
               request_headers,
               cache,
               shortner,
               base_url,
               use_gzip_compression,
               debugHTTP)

    def _InstallOpener(self, opener):
         proxies = {
                   'http': '%s:%s' % ('http://proxyhost', 80),
                   'https': '%s:%s' % ('http://proxyhost', 80),
                }

         proxy_handler = self._urllib.ProxyHandler(proxies)
         opener.add_handler(proxy_handler)

Original issue reported on code.google.com by si...@weston.net.au on 16 Aug 2011 at 12:12

Attachments:

GoogleCodeExporter commented 8 years ago
thanks for the patch!

Original comment by bear42 on 16 Aug 2011 at 6:01

GoogleCodeExporter commented 8 years ago
Can you please provide instructions on how to make python-twitter work behind a 
proxy? I tried almost everything. It is very crucial for my research. Thank you 
in advance...

Original comment by mour...@gmail.com on 29 Feb 2012 at 6:32