urllib2 through basic auth'ed proxy
Alejandro Dubrovsky
dubrovsky at physics.uq.edu.au
Sun Apr 2 21:40:26 EDT 2006
John J. Lee wrote:
> jjl at pobox.com (John J. Lee) writes:
>
>> Alejandro Dubrovsky <dubrovsky at physics.uq.edu.au> writes:
> [...Alejandro complains about non-working HTTP proxy auth in urllib2...]
>
> [...John notes urllib2 bug...]
>> A workaround is to supply a stupid HTTPPasswordMgr that always returns
>> the proxy credentials regardless of what the handler asks it for (only
>> tested with a perhaps-broken 2.5 install, since I've broken my 2.4
>> install):
> [...snip ugly code]
>> Yuck, yuck, yuck! I had realised the auth/proxies code in urllib2 was
>> buggy, but... And all those hoops to jump through.
>>
>> Also, if you're using 2.5 SVN HEAD, it seems revision 42133 broke
>> ProxyHandler in an attempt to fix the URL host:post syntax!
> [...]
>
> In fact the following also works with Python 2.3.4:
>
> import urllib2
> proxy_handler = urllib2.ProxyHandler({"http":
> "http://john:blah@localhost:3128"}) print
> urllib2.build_opener(proxy_handler).open('http://python.org/').read()
>
It does too. Thanks again. (I think this version is uglier, but easier to
insert into third party code)
More information about the Python-list
mailing list