How to ignore windows proxy settings with python urllib?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 14:59:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!