New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
websocket: message.json() fails with a TypeError when the message exceeds the size limit #7313
Comments
OK, I've been working through a PR to try and make this more type safe. 2 options we can do. First is to raise the exception from Second is to have |
Note that you can implement the second approach in your code now. My changes would just make it a requirement and flag up any issues when checked with mypy. |
I think I am puzzled (as a newbie aiohttp user) why the error is delivered as a message instead of a raised exception. |
I'm not too sure what the reasoning is for this, but you'll note from the websockets example that the expected behaviour is to check for WSMsgType.ERROR and then break (because the connection will be closed on an error): The data will only be an exception if the type is ERROR. Maybe @asvetlov can provide some reasoning why we don't raise the exception. |
Thanks, I've adjusted my code to check for |
Describe the bug
When a websocket message exceeds the size limit, calling message.json() raises a TypeError instead of an informative exception
To Reproduce
Send a large websocket message to an aiohttp server.
In the handler, calling message.json() raises TypeError:
message.data
is set to a WebSocketError instance:(I lowered the limit to more easily trigger the problem)
Expected behavior
I would expect calling
message.json()
to raise the WebSocketError.Logs/tracebacks
Python Version
Python 3.11.2
aiohttp Version
multidict Version
yarl Version
OS
macOS 10.15
Related component
Server
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: