繁体   English   中英

requests.exceptions.ConnectionError [Errno 11004] getaddrinfo在Python中使用请求失败。 浏览器工作

[英]requests.exceptions.ConnectionError [Errno 11004] getaddrinfo failed using Requests in Python. Browser works

我尝试使用python的请求库。 可悲的是,即使是最基本的步骤,我也未能通过。 我在这里查看了快速入门指南: http : //docs.python-requests.org/en/latest/user/quickstart/

以下代码失败:

import requests

r = requests.get('http://www.google.com')

有:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.google.com', port=80): 
Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x0000000003CC3BA8>: 
Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))

听起来好像我的网络有问题,但是在浏览器中打开相同的网页是可行的,所以这不是阻止我的原因,对吗?

PS从快速入门页面复制/粘贴示例并尝试打开“ https://api.github.com/events ”也会失败,并显示相同的错误。

我发现在我的公司中,他们某种程度上不为脚本请求提供DNS服务器。 这就是它不起作用的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM