Skip to content
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

Added extra error for when bytes_data is revieved #1456

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions channels/generic/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class JsonWebsocketConsumer(WebsocketConsumer):
def receive(self, text_data=None, bytes_data=None, **kwargs):
if text_data:
self.receive_json(self.decode_json(text_data), **kwargs)
elif not text_data and bytes_data:
raise ValueError("No text section for incoming WebSocket frame! There is a bytes section, however. Did you mean for it to be the text section?")
else:
raise ValueError("No text section for incoming WebSocket frame!")

Expand Down Expand Up @@ -257,6 +259,8 @@ class AsyncJsonWebsocketConsumer(AsyncWebsocketConsumer):
async def receive(self, text_data=None, bytes_data=None, **kwargs):
if text_data:
await self.receive_json(await self.decode_json(text_data), **kwargs)
elif not text_data and bytes_data:
raise ValueError("No text section for incoming WebSocket frame! There is a bytes section, however. Did you mean for it to be the text section?")
else:
raise ValueError("No text section for incoming WebSocket frame!")

Expand Down