urllib2 disable proxy

  • Thread starter Dimitrios Apostolou
  • Start date
D

Dimitrios Apostolou

Hello list,

I've been looking for a way to explicitly disable the use of proxies with
urllib2, no matter what the environment dictates. Unfortunately I can't find
a way in the documentation, and reading the source leads me to believe that
something like the following does the job:

req.set_proxy(None,None)

Where req is a urllib2.Request instance. So is there an official way of doing
this? Perhaps it should be added in the documentation?


Thanks in advance,
Dimitris
 
R

Rob Wolfe

Dimitrios Apostolou said:
Hello list,

I've been looking for a way to explicitly disable the use of proxies with
urllib2, no matter what the environment dictates. Unfortunately I can't find
a way in the documentation, and reading the source leads me to believe that
something like the following does the job:

req.set_proxy(None,None)

Where req is a urllib2.Request instance. So is there an official way of doing
this? Perhaps it should be added in the documentation?

I believe that the recommended way is to use `urllib2.ProxyHandler`.
Take a look at:
http://www.voidspace.org.uk/python/articles/urllib2.shtml

HTH,
Rob
 
D

Dimitrios Apostolou

I believe that the recommended way is to use `urllib2.ProxyHandler`.
Take a look at:
http://www.voidspace.org.uk/python/articles/urllib2.shtml

Thanks for the pointer, I will use that way. However it seems rather
non-elegant way to do something so simple and I was hoping not to mess
with ProxyHandler, especially since I want *no* proxy... IMHO something
like the following would be more elegant:

req.set_proxy('','http')

or

req.set_proxy(None,'http')


However these ways *don't* work. You think I should file a feature request
somewhere or send this to the python-dev list?


Thank you for the help,
Dimitris
 
R

Rob Wolfe

Dimitrios Apostolou said:
Thanks for the pointer, I will use that way. However it seems rather
non-elegant way to do something so simple and I was hoping not to mess
with ProxyHandler, especially since I want *no* proxy... IMHO
something like the following would be more elegant:

req.set_proxy('','http')

or

req.set_proxy(None,'http')


However these ways *don't* work. You think I should file a feature
request somewhere or send this to the python-dev list?

Actually, I like this idea of handlers and openers
and find it simple and _elegant_, so I can't second that request.
Besides disabling proxies despite environmental settings
is a special case, so imho using `instal_opener` is justified.

Regards,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top