python error: urlopen error [Errno 11001] getaddrinfo failed
python error: urlopen error [Errno 11001] getaddrinfo failed
我们正在使用代理。
我可以用下面的代码打开 http://www.google.com 和 www.bing.com。
但是,我在尝试打开其他网站时遇到错误 "urlopen error [Errno 11001] getaddrinfo failed",
例如:https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson, https://www.pythonprogramming.net,
www.aa.com,等等
http和https的规则相同,即http://MyCompanyProxy:Port/。
如何将 http 和 https 规则都设置为 http://MyCompanyProxy:Port/?
谢谢。
import urllib.request
def main():
urlData = "http://google.com/"
***edited****
proxy = urllib.request.ProxyHandler({'http': 'http://MyCompanyProxy:Port/','https': 'http://MyCompanyProxy:Port/'})
****end of edit*******
auth = urllib.request.HTTPBasicAuthHandler()
opener = urllib.request.build_opener(proxy, auth, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
webUrl = urllib.request.urlopen(urlData) #--->> error here
print ("result code: " + str(webUrl.getcode()))
if __name__ == "__main__":
main()
您也应该使用 'https' 规则调用 ProxyHandler。不仅'http'如果你想访问
我们正在使用代理。
我可以用下面的代码打开 http://www.google.com 和 www.bing.com。
但是,我在尝试打开其他网站时遇到错误 "urlopen error [Errno 11001] getaddrinfo failed", 例如:https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson, https://www.pythonprogramming.net, www.aa.com,等等
http和https的规则相同,即http://MyCompanyProxy:Port/。
如何将 http 和 https 规则都设置为 http://MyCompanyProxy:Port/?
谢谢。
import urllib.request
def main():
urlData = "http://google.com/"
***edited****
proxy = urllib.request.ProxyHandler({'http': 'http://MyCompanyProxy:Port/','https': 'http://MyCompanyProxy:Port/'})
****end of edit*******
auth = urllib.request.HTTPBasicAuthHandler()
opener = urllib.request.build_opener(proxy, auth, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
webUrl = urllib.request.urlopen(urlData) #--->> error here
print ("result code: " + str(webUrl.getcode()))
if __name__ == "__main__":
main()
您也应该使用 'https' 规则调用 ProxyHandler。不仅'http'如果你想访问