gpt4 book ai didi

python - 这个 Python 请求错误是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 19:26:46 25 4
gpt4 key购买 nike

这个 Python 请求错误是什么意思?这是否意味着它尝试连接到服务器但不能? [Errno 8] nodename nor servname provided, or not known 是什么意思?

File "python2.7/site-packages/requests/api.py", line 55, in get

File "python2.7/site-packages/requests/api.py", line 44, in request

File "python2.7/site-packages/requests/sessions.py", line 279, in request

File "python2.7/site-packages/requests/sessions.py", line 374, in send

File "python2.7/site-packages/requests/adapters.py", line 209, in send

ConnectionError: HTTPConnectionPool(host='localhost', port=8091): Max retries exceeded with url: /pools/default (Caused by : [Errno 8] nodename nor servname provided, or not known

代码生成了这个:http://github.com...

class RestConnection(object):
def __init__(self, serverInfo):
#serverInfo can be a json object
if isinstance(serverInfo, dict):
self.ip = serverInfo["ip"]
self.username = serverInfo["username"]
self.password = serverInfo["password"]
self.port = serverInfo["port"]
self.couch_api_base = serverInfo.get("couchApiBase")
else:
self.ip = serverInfo.ip
self.username = serverInfo.rest_username
self.password = serverInfo.rest_password
self.port = serverInfo.port
self.couch_api_base = None

self.base_url = "http://{0}:{1}".format(self.ip, self.port)
server_config_uri = ''.join([self.base_url, '/pools/default'])
self.config = requests.get(server_config_uri).json()
# if couchApiBase is not set earlier, let's look it up
if self.couch_api_base is None:
#couchApiBase is not in node config before Couchbase Server 2.0
self.couch_api_base = self.config["nodes"][0].get("couchApiBase")

仅供引用,此错误是从 Couchbase Python 客户端生成的。

最佳答案

这意味着您尝试访问的主机名的 DNS 查找失败。例如,如果我尝试查找无效的主机名,我会得到同样的错误:

>>> import requests
>>> requests.get('http://apsoapsodjaopisjdaoij.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 65, in get
return request('get', url, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/safe_mode.py", line 39, in wrapped
return function(method, url, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/api.py", line 51, in request
return session.request(method=method, url=url, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/sessions.py", line 241, in request
r.send(prefetch=prefetch)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/models.py", line 631, in send
raise ConnectionError(sockerr)
requests.exceptions.ConnectionError: [Errno 8] nodename nor servname provided, or not known

检查 serverInfo["ip"] 的值并确保其设置正确。

关于python - 这个 Python 请求错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15286288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com