我正在使用Python和Requests模块。但是每当我使用“requests.get”和URL时,我就会得到错误:
Traceback (most recent call last):
File "python", line 15, in <module>
requests.exceptions.ConnectionError: HTTPSConnectionPool
(host='www.google.com', port=443): Max retries exceeded with url: /?
safe=active&gws_rd=ssl&safe=active (Caused by NewConnectionError
('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at
0x7f86809a16a0>: Failed to establish a new connection: [Errno -2] Name or
service not known',))
这是我的代码:
try:
import requests
except ImportError:
print ("Error: MOD.01")
r = requests.session()
url = "https://www.google.com/?safe=active&gws_rd=ssl&safe=active"
r2 = requests.get(url)
是我的代码触发了这个错误吗? 谢谢。
您得到的错误是“名称或服务未知”。这意味着服务器找不到www.google.com的IP地址
确保正确复制/粘贴所有内容,然后从运行python脚本的同一个shell复制/粘贴下一个,查看是否可以ping www.google.com
这可能很简单,因为网络(或DNS)没有为该计算机/外壳配置。
相关问题 更多 >
编程相关推荐