No reconnection after ConnectionResetError(104, 'Connection reset by peer'))
See original GitHub issue- I have searched for other issues with the same problem or similar feature requests.
Select one:
- Bug
- Feature Request
- Technical Help
- Other
Environment
- Are you using the module on a VPS or other Cloud hosting?
- Are you using the module on a Raspberry Pi?
What kind of internet connection do you have?
My VPS provider is OnetSolution
Average system load (CPU)

Hardware specification

Operating System? (include version)
- macOS
- Windows
- Linux (include flavour) Debian
Options
- stream_buffer
- process_stream_data
Which endpoint do you connect?
binance.com-futures
Python Version Requirement
- I am using Python 3.7 or above
Exact Python Version?
Using this script inside docker container with image: python:3.8-slim-bullseye
Pip Version?
pip 21.2.4 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
Dependencies
aiohttp 3.7.4.post0
aniso8601 9.0.1
APScheduler 3.8.1
async-timeout 3.0.1
attrs 21.4.0
backports.zoneinfo 0.2.1
binance-futures 1.1.0
certifi 2021.10.8
chardet 4.0.0
charset-normalizer 2.0.10
cheroot 8.6.0
click 8.0.3
colorama 0.4.4
dateparser 1.1.0
discord 1.7.3
discord.py 1.7.3
Flask 2.0.2
Flask-RESTful 0.3.9
idna 3.3
itsdangerous 2.0.1
jaraco.functools 3.5.0
Jinja2 3.0.3
MarkupSafe 2.0.1
more-itertools 8.12.0
multidict 5.2.0
pip 21.2.4
psutil 5.9.0
python-binance 1.0.14
python-dateutil 2.8.2
pytz 2021.3
pytz-deprecation-shim 0.1.0.post0
redis 3.5.3
regex 2022.1.18
requests 2.27.1
setuptools 57.5.0
six 1.16.0
typing_extensions 4.0.1
tzdata 2021.5
tzlocal 4.1
ujson 5.1.0
unicorn-binance-websocket-api 1.35.0
unicorn-fy 0.11.0
urllib3 1.26.8
websocket-client 1.2.3
websockets 10.1
Werkzeug 2.0.2
wheel 0.37.0
yarl 1.7.2
UNICORN Binance WebSocket API Version?
Using 1.35.0 when it happened
Description of your issue
I have a simple futures userData stream running. Two days ago, this error happened in the log:
2022-02-20 07:50:48,955 [CRITICAL] BinanceWebSocketApiRestclient._request() - error: 9 - error_msg: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
My stream never seems to reconnect (No DISCONNECT message received, and no user data received as well). It took me two days to notice that I was not receiving any data. Everything was ok in the logs
I normally have a way to handle disconnection using “DISCONNECT” messages. I’m surprised I didn’t get any this time. Any idea why ?
Complete log:
These logs goes on during two days until restart of my script
[...]
2022-02-20 09:50:50,754 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
--
2022-02-20 09:50:50,754 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 09:20:50,470 [INFO] BinanceWebSocketApiManager._frequent_checks() - sent listen_key keepalive ping for stream_id=8081d15343fd-fd43-e9c4-6963-6520d467
2022-02-20 09:20:50,183 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
2022-02-20 09:20:50,182 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 08:50:49,898 [INFO] BinanceWebSocketApiManager._frequent_checks() - sent listen_key keepalive ping for stream_id=8081d15343fd-fd43-e9c4-6963-6520d467
2022-02-20 08:50:49,606 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
2022-02-20 08:50:49,605 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 08:20:49,417 [INFO] BinanceWebSocketApiManager._frequent_checks() - sent listen_key keepalive ping for stream_id=8081d15343fd-fd43-e9c4-6963-6520d467
2022-02-20 08:20:49,138 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
2022-02-20 08:20:49,137 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 07:50:48,955 [INFO] BinanceWebSocketApiManager._frequent_checks() - sent listen_key keepalive ping for stream_id=8081d15343fd-fd43-e9c4-6963-6520d467
2022-02-20 07:50:48,955 [CRITICAL] BinanceWebSocketApiRestclient._request() - error: 9 - error_msg: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
2022-02-20 07:50:48,910 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
2022-02-20 07:50:48,909 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 07:20:48,846 [INFO] BinanceWebSocketApiManager._frequent_checks() - sent listen_key keepalive ping for stream_id=8081d15343fd-fd43-e9c4-6963-6520d467
2022-02-20 07:20:48,557 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
2022-02-20 07:20:48,556 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 06:50:48,421 [INFO] BinanceWebSocketApiManager._frequent_checks() - sent listen_key keepalive ping for stream_id=8081d15343fd-fd43-e9c4-6963-6520d467
2022-02-20 06:50:48,139 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
2022-02-20 06:50:48,139 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 06:20:48,108 [INFO] BinanceWebSocketApiManager._frequent_checks() - sent listen_key keepalive ping for stream_id=8081d15343fd-fd43-e9c4-6963-6520d467
2022-02-20 06:20:47,836 [INFO] BinanceWebSocketApiRestclient.keepalive_listen_key(***SECRET_REMOVED***)
2022-02-20 06:20:47,835 [INFO] BinanceWebSocketApiRestclient.get_listen_key() stream_id='8081d15343fd-fd43-e9c4-6963-6520d467')
2022-02-20 07:14:08 | [{"symbol":"PEOPLEUSDT","positionAmt":"1633","entryPrice":"0.053331497198","markPrice":"0.05400000","unRealizedProfit":"1.09167683","liquidationPrice":"0.04837341","leverage":"10","maxNotionalValue":"100000","marginType":"isolated","isolatedMargin":"9.97816418","isAutoAddMargin":"false","positionSide":"BOTH","notional":"88.18200000","isolatedWallet":"8.88648735","updateTime":1645337647033}]
-- | --
Here a sample of my code:
def process_data(received_stream_data_json, stream_buffer_name):
if binance_websocket_api_manager_future.is_manager_stopping():
exit(0)
handle_crash(binance_websocket_api_manager_future)
if stream_buffer_name == stream_user_data:
process_user_data_message(received_stream_data_json)
def handle_crash(binance_websocket_manager):
stream_signal = binance_websocket_manager.pop_stream_signal_from_stream_signal_buffer()
if stream_signal is not False:
if stream_signal['type'] == "DISCONNECT":
msg_crashing = "Stream is crashing. Restarting..."
# Save crashing status
logging.error(msg_crashing)
time.sleep(int(parameters.restart_delay_seconds))
os.execv(sys.executable, ['python3'] + sys.argv) # Restart script
# create instance of BinanceWebSocketApiManager for Binance.com Futures
binance_websocket_api_manager_future = BinanceWebSocketApiManager(process_stream_data=process_data,
exchange="binance.com-futures",
enable_stream_signal_buffer=True)
# create the userData streams
stream_user_data = binance_websocket_api_manager_future.create_stream(["arr"],
["!userData"], stream_label="UserData",
stream_buffer_name=True,
api_key=parameters.api_key,
api_secret=parameters.api_secret)
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Python handling socket.error: [Errno 104] Connection reset ...
When using Python 2.7 with urllib2 to retrieve data from an API, I get the error [Errno 104] Connection reset by peer ....
Read more >[Errno 104] Connection reset by peer · Issue #778 · aio-libs ...
ConnectionError, RedisError which causes problems because ConnectionResetError is no longer a subclass of ConnectionError . If one looks at line 37 of client.py ......
Read more >What does the '(104) Connection reset by peer' error ...
It means that TCP reset has been sent to your computer. This happens for example when web server is restarted due to configuration...
Read more >connectionreseterror: [errno 104] connection reset by peer
The situation is somewhat similar to this expression: "Connection reset by peer" is the TCP/IP equivalent of slamming the phone back on the...
Read more >Getting intermittent error with message 'Connection reset ...
ConnectionResetError (104, 'Connection reset by peer'))", ... In this case, I think that the extractionID is still valid so you can reconnect ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
it looks good ! You can close it, thank you
Solved?