'websockets.exceptions.ConnectionClosedError: code = 1011 (unexpected error), no reason
The server close connection for the client after a while and client disconnect automatically after try to send a message :
newmsg = await websocket.recv()
Solution 1:[1]
the problem is the server is sending pings to the client and try to get a response which is the newmsg, when the msg is not sent back then the server close the connection after 20 sec which is the default value, the solution is to desactivate the ping from the server and the client if you want : server.py:
start_server = websockets.serve(receive_name, "localhost", 8765,ping_interval=None)
client.py :
async with websockets.connect(uri, ping_interval=None) as websocket:
Solution 2:[2]
Maybe it is not from your client side's code. Mine is from server side because of a typo. Should also check the server side's log and see if there is any error.
Solution 3:[3]
Mine case was handling wrong key by server side.
Server expected:
{
"data": 1,
"build_id": 43
}
but i send:
{
"data": 1,
"build": 43
}
so it can not handle build
key and error code was 1011
without reason.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Adil Saidi |
Solution 2 | Pak Ho Cheung |
Solution 3 | Bar?? ?enyerli |