python-binance: Non-catched Connection aborted.', OSError("(104, 'ECONNRESET')") error

Hi there, if I run the websocket for a while I occassionally get this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 1158, in run
    self.function(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/binance/websockets.py", line 473, in _keepalive_user_socket
    user_listen_key = self._client.stream_get_listen_key()
  File "/usr/local/lib/python3.7/site-packages/binance/client.py", line 2036, in stream_get_listen_key
    res = self._post('userDataStream', False, data={})
  File "/usr/local/lib/python3.7/site-packages/binance/client.py", line 210, in _post
    return self._request_api('post', path, signed, version, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/binance/client.py", line 181, in _request_api
    return self._request(method, uri, signed, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/binance/client.py", line 175, in _request
    response = getattr(self.session, method)(uri, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 559, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 495, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(104, 'ECONNRESET')"))

Unfortunately, since that error happens in the thread at arbitrary times I cannot catch it. Could you please implement a catch for that kind of exception? @sammchardy

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 59 (5 by maintainers)

Most upvoted comments

I also get this at least once a day, in Ubuntu

This cannot be headers, because requests/sockets works for period of time. But after you leave it for a minutes and try request again - it will give this error. It definetely from server side. Probably binance-python do not making pong anwers as Binance requires?

@ingega what is the error/traceback you sent them? I’ve been getting this error on a weekly basis for 3 years now and have tried sleeping then reconnecting which only works sometimes. I wonder if we are getting throttled?

Yeah, it’s fairly soul destroying. If we knew this error was exclusive to this library I’d consider rewriting in ccxt or something, but don’t really want to do that in case it’s actually a Binance issue.

Not been running bots recently, but back during summer I didn’t experience the issue at all when using the new web socket implementation on 1+. Had a script running on an AWS server for about 5 days with no interruptions. Maybe I just got lucky though!

in my experience, i had a better time using oliver-zehentleitner/unicorn-binance-websocket-api for websockets