访问Python请求中的错误URL时 Import请求 url =“ http://sdfsdfasdfsfsdf.com” res = requests.get(url) 如果res == 200: 打印(“确定”) 别的: 打印(“错误”) 如上所述,我想

问题描述 投票:0回答:1
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')
python python-requests
1个回答
0
投票

我认为您有一个互联网问题,您可以通过连接到Internet来解决此错误。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.