urllib2 : https and proxy

O.R.Senthil Kumaran orsenthil at users.sourceforge.net
Thu Jun 28 14:22:16 EDT 2007


> Hello all,
> 
> I'm facing a strange behavior of urllib2 trying to access gmail
> account behind a proxy (Squid).
> 

First off, your password wont work. See if you can get a new one. :-)
Then to setup proxy suppor for urllib2, do the steps:


 
            proxy_url = 'http://' + PROXY_USER + ':' + PROXY_PASSWORD + \
                '@' + PROXY_IP + ':' + PROXY_PORT
            proxy_support = urllib2.ProxyHandler({'http': proxy_url})
            opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
            urllib2.install_opener(opener)

Substitute PROXY_* with actual values and then do urllib2.urlopen(site) which will go through the proxy.
 
-- 
O.R.Senthil Kumaran
http://uthcode.sarovar.org



More information about the Python-list mailing list