Websocket Error: Исключение внутри приложения: объект 'set' не имеет атрибута 'decode'
Я изучаю Django для школьного проекта и пытаюсь создать сервер websocket, используя Django Channels с Daphne и Redis, но получаю ошибку "AttributeError: 'set' object has no attribute 'decode'"
При загрузке приложения происходит рукопожатие websocket и создается соединение, однако сразу после этого я отсоединяюсь от сервера со следующей ошибкой и трассировкой.
HTTP POST /chat/signin/ 200 [0.61, 127.0.0.1:54147]
WebSocket HANDSHAKING /chat/ [127.0.0.1:54149]
username True
WebSocket CONNECT /chat/ [127.0.0.1:54149]
Exception inside application: 'set' object has no attribute 'decode'
Traceback (most recent call last):
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/django/contrib/staticfiles/handlers.py", line 101, in __call__
return await self.application(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/routing.py", line 62, in __call__
return await application(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/security/websocket.py", line 37, in __call__
return await self.application(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/django_channels_jwt_auth_middleware/auth.py", line 36, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/sessions.py", line 47, in __call__
return await self.inner(dict(scope, cookies=cookies), receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/sessions.py", line 263, in __call__
return await self.inner(wrapper.scope, receive, wrapper.send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/auth.py", line 185, in __call__
return await super().__call__(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/middleware.py", line 24, in __call__
return await self.inner(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/routing.py", line 116, in __call__
return await application(
^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/consumer.py", line 94, in app
return await consumer(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/consumer.py", line 58, in __call__
await await_many_dispatch(
File "/Users/User/folder/projectFolder/env/lib/python3.12/site-packages/channels/utils.py", line 57, in await_many_dispatch
await task
AttributeError: 'set' object has no attribute 'decode'
WebSocket DISCONNECT /chat/ [127.0.0.1:54149]
Вот как настроен мой сервер
import chat.routing
import os
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django_channels_jwt_auth_middleware.auth import JWTAuthMiddlewareStack
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter({
'http': django_asgi_app,
'websocket': AllowedHostsOriginValidator(
JWTAuthMiddlewareStack(
URLRouter(chat.routing.websocket_urlpatterns)
)
)
})
Я пытался найти похожие вопросы, но все они вызывали атрибут decode, а я нет. Как я могу решить эту проблему?