Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/connection.py", line 72, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 954, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
你知道解决方案吗?可能是因为无法解析主机名
替代品可以尝试尝试以外的块
import requests
url = "http://sdfsdfasdfsfsdf.com"
try:
res = requests.get(url)
if res.status_code == 200:
print("ok")
else:
print('wrong')
except:
print('wrong')
我认为您有一个互联网问题,您可以通过连接到Internet来解决此错误。