I've been trying to use the python websocket-client module to receive and store continuous updates from an exchange. Generally, the script will run smoothly for a day or so before raising the following error: websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
I've looked at the websocket-client source code and apparently the error is being raised in line 92 by the code if not bytes_:. Furthermore, the WebSocketConnectionClosedException is supposed to be raised "If remote host closed the connection or some network error happened".
Can anybody tell me why this is happening, and what I could do to stop or handle it.
Most likely, the remote host closed the connection. You cannot stop it. You can handle it by re-connecting.
People running web servers will implement automatic cleanup to get rid of potentially stale connections. Closing a connection that's been open for 24 hours sounds like a sensible approach. And there's no harm done, because if the client is still interested, it can re-establish the connection. That's also useful to re-authenticate the client, if authentication is required.
On second thought, it might be a network disconnect as well. Some DSL providers used to disconnect and re-assign a new IP every 24 hours, to prevent users from running permanent services on temporarily assigned IP addresses. Don't know if they still do that.
"Connection is already closed." error with python WebSocket client