Error: Connection aborted, 'ECONNRESET', 104

Q: Why I’m getting an error message with ‘ECONNRESET’?
For example in Python: ('Connection aborted.', OSError("(104, )",))

ECONNRESET is a generic connection protocol error that is bound to happen eventually when using the REST or Streaming API (websocket). The cause can be numerous, including but not limited to:

  • The websocket session was not kept alive;
  • The limit for maximum streams or incoming messages was exceeded for the websocket connection;
  • There’s a connection interruption with the used proxy/firewall from user side;
  • The requested service address is incorrect;

Suggestion:
The handling varies due to different scenarios.
If using websocket, make sure the connection is stabilised and maintained by doing the necessary handshakes (sending pong frames) and check if the maximum streams per connection, as well as the maximum incoming messages are being respected. These limits can be different between Spot and Futures, please consult the API documentation for the detailed description.

If it’s related to unstable network in the middle of data transmission, you can try to rebuild the TCP session or ignore and retry. The user should be prepared for eventual failures on the Application Layer.

1 Like

Heyy, I make a python code and I have this error. The script show me the price once at hour (the first lap return the price perfect but the next hour the problem happend). I try to put try and except in the while loop to fix it but nothing. How can I refresh the session before to get the price ? Could be this: client = Client(credentials.api_key,credentials.secret_key) ? If this fix it obvisly.
Thanks

@Tomas_Marmay apologies for missing out your message, how’s the situation? What was the request you were doing?

Hope I’m not hijacking the thread - let me know and I’ll start another one if need be. I’ve run into this issue as well and found this post from your link on Telegram @aisling . This issue only seems to occur for me when using AWS EC2 - local machine seems to be ok but obviously not practical for an ‘always-on’ solution. For context, I call the REST API for futures pricing on around 12 coins once per minute and call account (weight 5) to track unrealised PnL and create a maximum of 12 orders (though this is unlikely) every minute so I’m nowhere near the limits…

Do you have a suggestion for a workaround?

I use python so have tried installing requests[security] which did seem to reduce the number of errors but still having the connection closed around once per day (and usually losing money as I have to manually close all open positions and restart).

I have also tried catching the error, skipping the iteration of the loop and waiting until the next minute to retry but that’s not ideal as I’m then working with out-of-date pricing info

Hi @BreadSauceSandwich, it’s hard to help on this error as it’s very dependant on your own environment setup specifications and your network.
Try to follow the usual troubleshooting process by obtain all necessary details (full error messages, when it gets disconnected, if handshake is working, number of messages, streams,…), do small tests to to see if you can find a pattern and exclude possibilities out until you find a more solid conclusion.

Thanks for the support @aisling - I’ll keep an eye out and try to remember to copy the error message here next time it occurs. I’ve just tweaked my code to reduce the weight of the calls per minute and added in some attempts to catch and handle the exception - will report back with the findings.