问题
I want Python to ignore Windows proxy settings when using urllib
. The only way I managed to do that was disabling all proxy settings on Internet Explorer. Is there any programmatic way?
os.environ['no_proxy']
is not a good option, since I'd like to avoid proxy for all addresses.
回答1:
Pass to urlopen method
proxies={}
or try with:
urllib.getproxies = lambda x = None: {}
just after urllib import (Info found here).
回答2:
From the urlib2 documentation: Class urllib2.ProxyHandler([proxies]) ... To disable autodetected proxy pass an empty dictionary.
So what we want to do is this:
import urllib2
proxy = urllib2.ProxyHandler({}) # Pass empty dictionary to bypass proxy
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
socket = urllib2.urlopen('http://www.google.com')
content = socket.read()
回答3:
According to document, you could pass, proxies=None or proxies={}
urllib.urlopen(some_url, proxies=None)
回答4:
I had trouble making request ignore the proxies. These did not work.
proxies=None or proxies={}
This did work
proxies={'http':None}
来源:https://stackoverflow.com/questions/2645372/how-to-ignore-windows-proxy-settings-with-python-urllib