urllib.urlopen and proxies

Siggy Brentrup bsb at winnegan.de
Thu Mar 8 13:56:42 CET 2001

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

> On Wed, 7 Mar 2001 13:44:11 +0100 , Siggy Brentrup <bsb at winnegan.de> wrote:
> >Paul Moore <paul.moore at uk.origin-it.com> writes:
> >Well, obviously I should have tested before posting :-( There's one
> >omission in my code as well as three typos in urllib2.py (sample and
> >patch attached)
> Hmm. I was using Python 2.0. I switched to Python 2.1, and applied your patch
> (did you send it to SourceForge as a bug report?

Sure, cf Bug #406683 "typos in urllib2"

> If not, would you like me to?) Running your script (with my proxy
> info) I still get an error...

> C:\Data>python21 proxy_auth.py
> Traceback (most recent call last):
>   File "proxy_auth.py", line 18, in ?
>     f = urllib2.urlopen('http://www.python.org/')
>   File "c:\applications\python21\lib\urllib2.py", line 135, in urlopen
>     return _opener.open(url, data)
>   File "c:\applications\python21\lib\urllib2.py", line 318, in open
>     '_open', req)
>   File "c:\applications\python21\lib\urllib2.py", line 297, in _call_chain
>     result = func(*args)
>   File "c:\applications\python21\lib\urllib2.py", line 822, in http_open
>     return self.do_open(httplib.HTTP, req)
>   File "c:\applications\python21\lib\urllib2.py", line 816, in do_open
>     return self.parent.error('http', req, fp, code, msg, hdrs)
>   File "c:\applications\python21\lib\urllib2.py", line 344, in error
>     return self._call_chain(*args)
>   File "c:\applications\python21\lib\urllib2.py", line 297, in _call_chain
>     result = func(*args)
>   File "c:\applications\python21\lib\urllib2.py", line 425, in
> http_error_default
>     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
> urllib2.HTTPError: HTTP Error 407: Proxy Authentication Required

> I dumped out a few of the objects, and it looks like the request is
> sending a Proxy-Authorization header to the proxy, with the
> base64-encoded user ID and password in it. Is there any chance my
> proxy doesn't work that way, and requires a different form of
> authorisation? I know nothing much about proxies, but I seem to
> recall seeing "Squid" in some of the proxy messages - is Squid a
> type of proxy????

Yes, I'm running Squid as my proxy too and _I'm_in_control_of_it_.
Your proxy setup might use some other form of authentication, what
urllib2.ProxyHandler uses, looks like "Basic HTTP Authentication" to
me - no time to investigate further now.

> If this is some sort of bizarre peculiarity of my proxy setup, then
> feel free to drop the issue - I can live without getting this to
> work, and I don't want to take up too much of your time with this.

Don't worry, I'll take this as an opportunity to learn about proxy
authentication, I'll look into it this weekend.

> Thanks for all the help you've provided so far - I feel that I at least
> understand the problem much better now...!

You're welcome


More information about the Python-list mailing list