18

What does this Python requests error mean? Does this mean it tries to connect to the server and couldn't? What does [Errno 8] nodename nor servname provided, or not known mean?

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

The code generated this: 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")

FYI, This error is generated from the Couchbase Python client.

1
  • 1
    Could you paste some surrounding code that triggered it? Commented Mar 8, 2013 at 4:27

5 Answers 5

11

Adding my own experience for those who are experiencing this in the future.

It turns out that this was actually because I had reach the maximum number of open files on my system. It had nothing to do with failed connections, or even a DNS error as indicated.

Sign up to request clarification or add additional context in comments.

2 Comments

How did you resolve this? I think I'm running into the same issue.
Honestly, I can't remember. I probably google something like "increase number of open files linux" and followed those directions.
9

It means the DNS lookup of the host name you're trying to access failed. For example, I get the same error if I try to look up an invalid host name:

>>> 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

Check the value of serverInfo["ip"] and make sure it's set correctly.

Comments

1

I was getting this error when trying to connect to .onion sites and it turns out that all I had to do was put "h" in front of the name of my socks proxies like this:

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

This might not be your solution but I am posting this answer just in case someone with the same problem as me comes looking for the solution here

Comments

0

Incorrect DNS, for e.g. when using a docker service and calling http://host.docker.internal:8000 instead of http://localhost:8000 when your are not on the docker service itself.

Comments

0

If you are here because the twitter api gave this error, try regenerating your Bearer token and it will work fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.