Python Forum

Full Version: Prevent urllib.request from using my local proxy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Using the code below I can still pull a page from the web. Where you see:
'xxxx'

Should be a valid proxy.
proxy_handler = urllib.request.ProxyHandler({'http': 'xxxx'}) 
opener = urllib.request.build_opener(proxy_handler)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)  
urllib.request.urlopen(url) 
and using 'xxxx' I should get an exception on the last line, but it continues to execute and pull the page. The reason for this is found here: https://www.decalage.info/en/python/urllib2noproxy

"If no proxy is explicitly specified, urllib2 will use Internet Explorer proxy settings by default."

BUT... even though I "do" explicitly specify a proxy (a known bad proxy) it will still revert to using my proxy and continue executing.

I need to prevent it from using any local proxy and "Only" the proxy I pass in. If it fails I need to know, log it and try another proxy.

Can someone please tell me how to block it from using my local proxy?

Thank you.