这个Python请求错误意味着什么?

时间:2013-03-08 03:37:55

标签: python couchbase

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

  

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

     

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

     

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

     

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

     

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

     

ConnectionError:HTTPConnectionPool(host ='localhost',port = 8091):Max   url:/ pools / default超出了重试次数(由:[Errno 8]提供nodename或servname,或者没有   已知

代码生成了这个: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 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:2)

为以后遇到这种情况的人增加我自己的经验。

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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