Can I catch websockets exception?
See original GitHub issueHI, I try to catch an exception “Connection reset by peer” when server-client is on heartbeat phase; unfortunately, I can not get the exception of websockets object via class ChargePoint. How can I do? Thanks I try to modify the code like this
async def start(self):
while True:
try:
message = await self._connection.recv()
LOGGER.info('%s: receive message %s', self.id, message)
await self.route_message(message)
except self._connection.exceptions as e: #fail
print('websockets.exceptions')
except IOError as err:
print(self.id, 'disconnected')
finally:
pass
error message like this
File "C:\Users\W8-PC\AppData\Local\Programs\Python\Python37\lib\asyncio\selector_events.py", line 801, in _read_ready__data_received data = self._sock.recv(self.max_size) ConnectionResetError: [WinError 10054]
and
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Exceptions - websockets 10.4 documentation
websockets.exceptions defines the following exception hierarchy: ... Raised to abort the handshake on purpose and return a HTTP response. This exception is an ......
Read more >Handling websockets module exceptions and errors
I'm trying to create a simple WebSocket server using websockets ... I don't really understand how can I catch those exceptions thrown by ......
Read more >Python websockets.exceptions.ConnectionClosed() Examples
This page shows Python examples of websockets.exceptions. ... Can raise ConnectionClosed data: Data = await self.websocket.recv() # websocket.recv() can ...
Read more >WebSockets - Handling Errors
WebSockets - Handling Errors, Once a connection has been established between the client and the server, an open event is fired from the...
Read more >WebSocket: error event - Web APIs | MDN
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
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
Happy to help! I will open this ticket now. Feel free to open a new one if you have more questions.
Hey @OrangeTux I know this issue is closed but I was wondering if you could help me with something similar to your answer above to monitor a web3 node WebSocket connection in the background while the rest of the code runs and can auto-reconnect when it disconnects.
Here’s how I connect currently:
Thanks in advance!