467,907 Members | 1,681 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,907 developers. It's quick & easy.

urllib2 and proxy question

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

Jul 18 '05 #1
  • viewed: 3241
Share:
4 Replies
rbt
Fuzzyman wrote:
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={})
Jul 18 '05 #2

rbt wrote:
Fuzzyman wrote:
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={})


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

Jul 18 '05 #3

rbt wrote:
Fuzzyman wrote:
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={})


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

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

Jul 18 '05 #4

rbt wrote:
Fuzzyman wrote:
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={})


The correct equivalent for urllib2 (in answer to my question !) is :
proxy_support = urllib2.ProxyHandler({})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)


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

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

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by O. Koch | last post: by
4 posts views Thread by bmiras | last post: by
reply views Thread by Lee, Dustin | last post: by
1 post views Thread by Ray Slakinski | last post: by
6 posts views Thread by Alejandro Dubrovsky | last post: by
3 posts views Thread by itay_k | last post: by
1 post views Thread by Alessandro Fachin | last post: by
6 posts views Thread by Jack | last post: by
1 post views Thread by Larry Hale | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.