![]() |
Prevent urllib.request from using my local proxy - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Prevent urllib.request from using my local proxy (/thread-33426.html) |
Prevent urllib.request from using my local proxy - spacedog - Apr-24-2021 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. |