urllib2 and proxy question

F

Fuzzyman

urllib2 (under windows) will auto-detect your proxy settings and use
those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and
wanting to test things *locally*. IE is set to not use the proxy when
fetching local adresses, but urllib2 ignores that part of the setting
and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it
to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
 
R

rbt

Fuzzyman said:
urllib2 (under windows) will auto-detect your proxy settings and use
those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and
wanting to test things *locally*. IE is set to not use the proxy when
fetching local adresses, but urllib2 ignores that part of the setting
and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it
to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

"Alternatively, the optional proxies argument may be used to explicitly
specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen(some_url, proxies={})
 
F

Fuzzyman

rbt said:
"Alternatively, the optional proxies argument may be used to explicitly
specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen(some_url, proxies={})

Wikkid... I'll try that. Nice one, thanks for your help.
It *still* means I have to have a different version for testing locally
- but it's better than the alternative.
Regards,


Fuzzy
http://www.voidspace.org.uk/python/index.shtml
 
F

Fuzzyman

rbt said:
"Alternatively, the optional proxies argument may be used to explicitly
specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen(some_url, proxies={})

Rats.. this answer is for urllib - *NOT* urllib2 !
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
 
F

Fuzzyman

rbt said:
"Alternatively, the optional proxies argument may be used to explicitly
specify proxies.
It must be a dictionary mapping scheme names to proxy URLs, where an
empty dictionary causes no proxies to be used"

# Don't use any proxies
filehandle = urllib.urlopen(some_url, proxies={})

The correct equivalent for urllib2 (in answer to my question !) is :

which is slightly more complicated but does exactly the same job !
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
 

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,014
Latest member
BiancaFix3

Latest Threads

Top