14

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

文件“python2.7/site-packages/requests/api.py”,第 55 行,在 get

请求中的文件“python2.7/site-packages/requests/api.py”,第 44 行

文件“python2.7/site-packages/requests/sessions.py”,第 279 行,在请求中

文件“python2.7/site-packages/requests/sessions.py”,第 374 行,在发送中

文件“python2.7/site-packages/requests/adapters.py”,第 209 行,在发送中

ConnectionError: HTTPConnectionPool(host='localhost', port=8091): Max retries exceeded with url: /pools/default (由: [Errno 8] nodename or 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 客户端生成的。

4

5 回答 5

7

这意味着您尝试访问的主机名的 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"]并确保其设置正确。

于 2013-03-08T04:55:32.910 回答
7

为将来遇到这种情况的人添加我自己的经验。

事实证明,这实际上是因为我已经达到了系统上打开文件的最大数量。它与失败的连接无关,甚至与所示的 DNS 错误无关。

于 2019-08-22T22:08:35.020 回答
0

如果您在这里是因为 twitter api 给出了这个错误,请尝试重新生成您的 Bearer 令牌,它会正常工作。

于 2020-11-29T20:39:10.207 回答
0

不正确的 DNS,例如当使用 docker 服务并调用http://host.docker.internal:8000而不是http://localhost:8000当您不在 docker 服务本身时。

于 2019-11-11T17:15:11.440 回答
0

我在尝试连接到 .onion 站点时遇到了这个错误,事实证明我所要做的就是在我的 socks 代理名称前面加上“h”,如下所示:

proxies = {
    'http':  'socks5h://127.0.0.1:9050',
    'https': 'socks5h://127.0.0.1:9050'
    }

这可能不是您的解决方案,但我发布此答案以防万一遇到与我相同问题的人在这里寻找解决方案

于 2022-01-04T14:21:31.320 回答