python错误:urlopen错误[Errno 11001] getaddrinfo失败

时间:2019-05-08 14:41:06

标签: python python-3.x web-scraping urllib

我们正在使用代理。

我可以使用以下代码打开http://www.google.com和www.bing.com。

但是,尝试打开其他网站时出现错误“ urlopen错误[Errno 11001] getaddrinfo失败”, 例如:https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojsonhttps://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()

1 个答案:

答案 0 :(得分:0)

您也应该使用“ https”规则调用ProxyHandler。如果您要访问的不仅是“ http”

相关问题