urllib.urlopen and proxies

Paul Moore paul.moore at uk.origin-it.com
Tue Mar 6 15:47:57 CET 2001

On Mon, 5 Mar 2001 16:07:42 +0100 , Siggy Brentrup <bsb at winnegan.de>

>"Chris Gonnerman" <chris.gonnerman at usa.net> writes:
>> It *appears* (from reading the source) that username and password
>> information for
>> the proxy server must be passed as part of the URL:
>>     http://username:password@my.host.com/index.html
>I suggest using urllib2, changing the proxy setup described in the
>module's docstring to
>  proxy_support = urllib2.ProxyHandler({"http" :
>                                        "http://user:pw@proxy:port"})
>Untested too, since my proxy doesn't require authorization.

I had a look at urllib2. The module docstring even includes an

import urllib2
# set up authentication info
authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password('realm', 'host', 'username', 'password')
proxy_support = urllib2.ProxyHandler({"http" :
# build a new opener that adds authentication and caching FTP handlers
opener = urllib2.build_opener(proxy_support, authinfo,
# install it
f = urllib2.urlopen('http://www.python.org/')

The only problem is that I don't know what the 'realm' and 'host'
parameters to authinfo.add_password should be. I need to supply a
username and password for everything...


More information about the Python-list mailing list