GetStream / stream-python

Python Client - Build Activity Feeds & Streams with GetStream.io
https://getstream.io
BSD 3-Clause "New" or "Revised" License
141 stars 41 forks source link

Max retries exceeded with url / connection refused #129

Closed getadapt closed 3 years ago

getadapt commented 3 years ago

Problem explanation

I'm getting Max retries exceeded with url on all api calls... I'm following the steps and tried in a few different python environments so I'm not sure where to go from here...

Steps to reproduce

client = stream.connect(API_KEY, API_SECRET, location='dublin') userfeed = client.feed('user', user.id) activities = userfeed.get(limit=5)

Environment info

Operating System: OSX 11.5.2 Big Sur Python version: 3.9.7 Library version: 5.1.0

Error traceback (if applicable)

Traceback (most recent call last):
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1279, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1325, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1274, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1034, in _send_output
    self.send(msg)
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 974, in send
    self.connect()
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/connection.py", line 200, in connect
    conn = self._new_conn()
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x123dee430>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/urllib3/util/retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /api/v1.0/feed/user/0kL1YwOp9jX39qNU5kQmrgfivAf2/?api_key=[redacted]&limit=5 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x123dee430>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/williammarsey/Sites/api/manage.py", line 21, in <module>
    main()
  File "/Users/williammarsey/Sites/api/manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/williammarsey/Sites/api/notifications/management/commands/run_for_firestore.py", line 19, in handle
    activities = userfeed.get(limit=5)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/stream/feed.py", line 139, in get
    return self.client.get(feed_url, params=params, signature=token)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/stream/client.py", line 294, in get
    return self._make_request(self.session.get, *args, **kwargs)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/stream/client.py", line 223, in _make_request
    response = method(
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/Users/williammarsey/.local/share/virtualenvs/api-Zq0bzdOW/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /api/v1.0/feed/user/0kL1YwOp9jX39qNU5kQmrgfivAf2/?api_key=[redacted]&limit=5 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x123dee430>: Failed to establish a new connection: [Errno 61] Connection refused'))

Code snippet that causes the problem

client = stream.connect(API_KEY, API_SECRET, location='dublin') # the stream site, when you click the "Integration <>" button said to use location='us-east' for this command but I think that's just an error on the stream site?
db = firestore.client()

for prof in db.collection('profiles').where('streamEnabled', '==', True).stream():
    print('userid', prof.id)
    userfeed = client.feed('user', prof.id)

    activities = userfeed.get(limit=5)
ferhatelmas commented 3 years ago

Server is denying establishing a connection with you because you might be sending too many requests in a short period of time. You can throttle your requests a bit or catch it and retry again.

You can also share your apikey with me (public is fine) and I can check your traffic.