-
-
Notifications
You must be signed in to change notification settings - Fork 801
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
Error with send_json Function in AsyncJsonWebsocketConsumer #2100
Comments
After examining the code within the parent class (AsyncJsonWebsocketConsumer), I noticed that the encoding process for the content using json.dumps(content) was utilizing the await keyword. However, I found that removing the await and simply using json.dumps resolved the error. This adjustment allowed the "welcome message" to be sent successfully to the client side without encountering any error. |
The de82aaa#diff-8adaf2e6e01ec2cc05dd10bfd212d6dddfadabe0ddc679b821e03024806647b7R254-R256
|
Error explanation: When we call Here is the error message: If I am misunderstanding something, please let me know. |
It looks like you've overridden a method maybe and forgotten an Please post code rather than screenshots. The async send_json method is covered by the test suite. If you could add a test demonstrating your issue, that would help to identify what you're seeing. |
The error traceback is as follows:
The full Here is a video demo of the error. Screencast.from.2024-05-20.17-22-47.webm |
Compare your class: to the base class: channels/channels/generic/websocket.py Lines 288 to 290 in 42deaca
By overriding this method without using the |
Environment Details:
Operating System:
Ubuntu 24.04 LTS
Browser:
Google Chrome
Django version:
5.0.4
Channels version:
4.1.0
pip freeze output:
asgiref==3.8.1 asyncpg==0.29.0 attrs==23.2.0 autobahn==23.6.2 Automat==22.10.0 cffi==1.16.0 channels==4.1.0 channels-redis==4.2.0 constantly==23.10.4 cryptography==42.0.5 daphne==4.1.2 Django==5.0.4 django-cors-headers==4.3.1 django-redis==5.4.0 djangorestframework==3.15.1 djangorestframework-simplejwt==5.3.1 hyperlink==21.0.0 idna==3.7 incremental==22.10.0 msgpack==1.0.8 psycopg2-binary==2.9.9 pyasn1==0.6.0 pyasn1_modules==0.4.0 pycparser==2.22 PyJWT==2.8.0 pyOpenSSL==24.1.0 python-dotenv==1.0.1 redis==5.0.3 service-identity==24.1.0 setuptools==69.5.1 six==1.16.0 sqlparse==0.5.0 Twisted==24.3.0 txaio==23.1.1 typing_extensions==4.11.0 whitenoise==6.6.0 zope.interface==6.3
Expected Behavior:
I anticipated that upon establishing a connection using AsyncJsonWebsocketConsumer, a "welcome message" would be successfully sent to the client side, similar to the behavior observed with JsonWebsocketConsumer.
Expected Behavior Code using JsonWebsocketConsumer:
Expected Response:
Actual Behavior:
I anticipated that upon establishing a connection using AsyncJsonWebsocketConsumer, a "welcome message" would be successfully sent to the client side, similar to the behavior observed with JsonWebsocketConsumer.
Actual Behavior Code:
Error Encountered:
The error encountered is as follows:
The text was updated successfully, but these errors were encountered: