I see from googling around that this is a popular topic, but I haven't seen
anyone saying "ah, yes, that works", so here it goes.
How does one connect through a proxy which requires basic authorisation?
The following code, stolen from somewhere, fails with a 407:
proxy_handler = urllib2.ProxyHa ndler({"http" :
"http://the.proxy.addre ss:3128"})
proxy_auth_hand ler = urllib2.ProxyBa sicAuthHandler( )
proxy_auth_hand ler.add_passwor d("The name of the realm sniffed from
telnetting to the proxy and doing a
get",'the.proxy .address','theu sername','thepa ssword')
opener = urllib2.build_o pener(proxy_han dler, proxy_auth_hand ler)
urllib2.install _opener(opener)
f = urllib2.urlopen ('http://www.google.com/')
I still get a 407 if I set the realm to None, I change host to the
'http://the.proxy.addre ss/' form or even 'http://the.proxy.addre ss:3128'
form.
The proxy is squid. Python version is 2.3.4 (I read that this version has a
problem in that it introduces an extra return after the authorisation, but
it isn't even getting to that bit). And yes, going through firefox,
everything works fine.
Can anyone explain me why this fails, or more importantly, code that would
work?
Thanks,
alejandro
anyone saying "ah, yes, that works", so here it goes.
How does one connect through a proxy which requires basic authorisation?
The following code, stolen from somewhere, fails with a 407:
proxy_handler = urllib2.ProxyHa ndler({"http" :
"http://the.proxy.addre ss:3128"})
proxy_auth_hand ler = urllib2.ProxyBa sicAuthHandler( )
proxy_auth_hand ler.add_passwor d("The name of the realm sniffed from
telnetting to the proxy and doing a
get",'the.proxy .address','theu sername','thepa ssword')
opener = urllib2.build_o pener(proxy_han dler, proxy_auth_hand ler)
urllib2.install _opener(opener)
f = urllib2.urlopen ('http://www.google.com/')
I still get a 407 if I set the realm to None, I change host to the
'http://the.proxy.addre ss/' form or even 'http://the.proxy.addre ss:3128'
form.
The proxy is squid. Python version is 2.3.4 (I read that this version has a
problem in that it introduces an extra return after the authorisation, but
it isn't even getting to that bit). And yes, going through firefox,
everything works fine.
Can anyone explain me why this fails, or more importantly, code that would
work?
Thanks,
alejandro
Comment