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

Created on 15 Apr 2019  路  47Comments  路  Source: sammchardy/python-binance

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

Most helpful comment

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

All 47 comments

PS: I found in this issue
https://stackoverflow.com/questions/43165341/python3-requests-connectionerror-connection-aborted-oserror104-econnr
that the error could be because of non-specified headers.

Hi occasionally get this too with REST on windows. Could be Binance's side?

I'm seeing this error on CentOS so it's not OSX specific

I get this error on 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?

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

Same here, ubuntu, every 10 min or so.

same here, telegram bot script, every 10 seconds polled, with sometimes edit or new messages,,mostly runs the whole day..mostly at night (not only night) suddenly it crshes..

also a crash always happens at dsl disconnect time, but why does t crash outside of the disconenc,t why mostly at night..

and why i cant get this catched

just seeing this error the first time. (ubuntu). Any idea what it is?

Still same issue, has anyone solved it? It happens at random times, sometimes it works minutes, sometimes hours, and sometimes days without giving this error

Has anyone solved it?

I had this also now on a very stable internet connection. Maybe its on binance side when they deploy an update and restart their services...

Could be the reason yes...the binance system had problems today.

I suggest you read the dates posted, nothing to do with today

Oliver wrote that he had the error now...und he postet it 2hours ago so I assumed he got it today

Yes but the problem has been happening for months, this is not the only thread with the same problem and no one has been able to solve it

finally it just means, the endpoint resetet the connection. binance docs are saying, they will do it every ~24 hours. so thats ok. it should get fetched and the connection reestablished..

Has anyone been able to figure this out? I've tried resetting the connection every 30 minutes which seems to mitigate the issue but not completely solve it.

Having the same problem

same issue, looks like it appeared at utc midnight time but I am not sure...
Is it some kind of binance api reset or have somebody found out how to fix this?

Hi,
I have the exact same issue... my script is the same as exposed here.
Have someone a solution ?
Thanks

@WHug0 If possible switch to Websockets instead of using REST API. At least thats what I did and now it seems to be working fine.

@Mindeliu what's the difference between WebSockets and Rest API ? I'm new here ^^

@WHug0

WebSockets provide a persistent connection between a client and server that both parties can use to start sending data at any time.

In other words, instead of making a request to a server every time you need to get data (In my case every couple seconds), you open a connection to a said server and it send the data to you when something changes without any additional requests.

@Mindeliu ok understood, thx a lot for all the explanations !

Websockets doesn't solve this issue...

anyone can help to provide a script that reproduce this issue? thanks

I got today the same error when using client.aggregate_trade_iter() to get historical trades from BNBBTC market.
I explicitly mention the symbol here, since I had no probs at all with the exact same procedure and versions reading other symbols data.
Python: 3.8.2
python-binance: 0.7.5

Also did get it when using CoinGecko python wrapper.. The code where this error happened is commented but previously wasn't.. This might be common. A temporary solution would be a try/except with a retry

Does anyone get this issue while using CCXT or just python-binance?

Hi It麓s november and the same error raise every time, some times it麓s every hours, some times it's every days, so, i try to do something like

try:
my_code
except:
time.sleep(1)
#return to my _code here

but appears doesn麓t work, so, it麓s awfull because your bot stop work ;(

Some one has found a solution?

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

mmmm i think in this solution, what麓s your opinion, first i try ping, if work, run my rutine, else i can wait 100 ms, something like:

try:
client.ping
#run my rutine
except:
time.sleep(0.1) #100 ms would be enough?

maybe?

i just write to binance help, but i've receveid these one:

CS Land (Binance)

Nov 19, 2020, 0:20 GMT+8

Dear user,

Thanks for reaching out.

Since the error you provided has been processed by your program, we couldn't for sure whether it caused by the incorrect request or the network issue.

We recommend you record the raw error message that responds from the server. Then we could check for you further.

Thank you for your understanding, we are looking forward to hearing from you soon.

Best Regards,
Binance Support Team

mmmm souspicius!!!! a lot of users had the same error? i don't think so!!!

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

Yeahhh @ddeanto i think the same, and maybe exist posibilitie, this API (python-binance) raise the error? maybe we must try with another api and tried it, but sincerily, this is the most complete api for binance, well, maybe worth it

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

Need to re-initialize the session after encountering this problem which means you should re-do below:
client = Client('xxxx','xxxx')

@blacksabbather Does that always solve it? Or it can still fail sometimes, like the other workarounds?

@blacksabbather Does that always solve it? Or it can still fail sometimes, like the other workarounds?

I advised one user to do that and the user never complained about it ever since

@blacksabbather Do you have a working catch in your own code?
I tried filtering each endpoint in my bot Class through a function like this:

def handle_connection_error(self, endpoint, timeout = 60):
    start_time = time.time()
    while True:
        try:
            return endpoint
        except ConnectionError:
            if time.time() > start_time + timeout:
                raise Exception(f'Unable to get updates after {timeout} seconds of ConnectionError.')
            else:
                self.init_client()
                time.sleep(1)

but I always get the ECONRESET error without it reconnecting or raising my own exception. Anyone got ideas as to what might be going wrong?

Need to re-initialize the session after encountering this problem which means you should re-do below:
client = Client('xxxx','xxxx')

Thanks, this works for me. Catch exception, sleep some, re-initialize Client. It still doesn't solve issue, but is a good workaround.

i just write to binance help, but i've receveid these one:

CS Land (Binance)

Nov 19, 2020, 0:20 GMT+8

Dear user,

Thanks for reaching out.

Since the error you provided has been processed by your program, we couldn't for sure whether it caused by the incorrect request or the network issue.

We recommend you record the raw error message that responds from the server. Then we could check for you further.

Thank you for your understanding, we are looking forward to hearing from you soon.

Best Regards,
Binance Support Team

mmmm souspicius!!!! a lot of users had the same error? i don't think so!!!

More likely issue is on our side (python-binance)

Dear lord can somebody fix this, I will pay them a BNB coin. This bug is ruining my life. If not, I will have time to look into it maybe in April. @kimchirichie you seem active lately, do you have any thoughts on this?

Dear lord can somebody fix this, I will pay them a BNB coin. This bug is ruining my life. If not, I will have time to look into it maybe in April. @kimchirichie you seem active lately, do you have any thoughts on this?

Hi,

I'm facing this issue. I'll let you know if I figure out what's happening on the back stage, checking python-binance at the moment.

Regards.

could this be related to the X-MBX-USED-WEIGHT values in the headers' response ? I haven't seen any test on this in the python code (_handle_response())

my 2 cents...

I'm having the same issue only on Ubuntu every 2 minutes or so. Running my code on Windows only produces this issue if Windows goes to sleep.

I HAVE been facing and dealing with this issue since last march , the only workaround i've found is to rerun my script after crash to the point he where !! i did not use python-binance library but i was facing the same problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ayy1337 picture ayy1337  路  6Comments

bilgecetin picture bilgecetin  路  6Comments

rightx2 picture rightx2  路  4Comments

terenceljz picture terenceljz  路  3Comments

.
Rob-bb picture Rob-bb  路  6Comments