urllib.urlopen and proxies

Siggy Brentrup bsb at winnegan.de
Tue Mar 6 13:05:35 EST 2001


Paul Moore <paul.moore at uk.origin-it.com> writes:

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

[...]

> >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
> example!
> 

[...]

> 
> 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...

The authinfo stuff is for remote sites requiring authentication, as
long as you visit unprotected sites only you can ignore it.

Modify the docstring example as follows:

--------
import urllib2

proxy_info = {
    'user' : 'your userid',
    'pass' : 'your password',
    'host' : "proxy.doma.in',
    'port' : 3128 # or 8080 or whatever
}
 
# build a new opener that uses a proxy requiring authorization
proxy_support = urllib2.ProxyHandler({"http" :
                "http://%(user)s:%(pass)s@%(host)s:%(port)d" % proxy_info})
opener = urllib2.build_opener(proxy_support)
 
# install it
urllib2.install_opener(opener)
 
f = urllib2.urlopen('http://www.python.org/')
--------

Proxy authorization still untested, please report if it works.

Siggy





More information about the Python-list mailing list