Getting the "Close" message. #6710
Unanswered
emanuele3d
asked this question in
Q&A
Replies: 1 comment
-
Having looked at the code a little better, the suggestion above would also help to discriminate between the case where the loop ends because of the three closure messages and the case where a WebSocketError exception is thrown by the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all apologies for opening a bug report (issue #6707) for something that wasn't a bug.
Thank you @Dreamsorcerer for pointing me to the relevant code though.
Assuming this code as context:
during normal operations the
ClientWebSocketResponse.__anext__
method returns the message received by the client andself.handle()
processes it. But I'm guessing if the server sends a message of type WSMsgType.CLOSE, WSMsgType.CLOSING, WSMsgType.CLOSED, theasync for
loop ends due to theraise StopAsyncIteration
and for that last message theself.handle()
method is not called.The closure message can be quite important though. I.e. the server I'm dealing with might issue a closing message asking me to -not- attempt reconnection for, say, 10 minutes instead of attempting reconnection after a few seconds. Attempting to reconnect too soon might result in administrative actions such as a temporary or permanent ban.
So, is there a way to access that last message in full? I notice the
ClientWebSocketResponse
class has aclose_code
property, which helps, but is not the full message.If there is no way, could this simple change to the
ClientWebSocketResponse.__anext__
code be acceptable:Beta Was this translation helpful? Give feedback.
All reactions