'How to remove this error 'No application configured for scope type 'websocket''
I am trying to build a chat app with Django but when I try to run it I get this error
No application configured for scope type 'websocket'
my routing.py file is
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter , URLRouter
import chat.routing
application = ProtocolTypeRouter({
# (http->django views is added by default)
'websocket':AuthMiddlewareStack(
URLRouter(
chat.routing.websocket_urlpatterns
)
),
})
my settings.py is
ASGI_APPLICATION = 'mychat.routing.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
when I open my URL in 2 tabs I should be able to see the messages that I posted in the first tab appeared in the 2nd tab but I am getting an error
[Failure instance: Traceback: <class 'ValueError'>: No application configured for scope type 'websocket'
/home/vaibhav/.local/lib/python3.6/site-packages/autobahn/websocket/protocol.py:2801:processHandshake
/home/vaibhav/.local/lib/python3.6/site-packages/txaio/tx.py:429:as_future
/home/vaibhav/.local/lib/python3.6/site-packages/twisted/internet/defer.py:151:maybeDeferred
/home/vaibhav/.local/lib/python3.6/site-packages/daphne/ws_protocol.py:82:onConnect
--- <exception caught here> ---
/home/vaibhav/.local/lib/python3.6/site-packages/twisted/internet/defer.py:151:maybeDeferred
/home/vaibhav/.local/lib/python3.6/site-packages/daphne/server.py:198:create_application
/home/vaibhav/.local/lib/python3.6/site-packages/channels/staticfiles.py:41:__call__
/home/vaibhav/.local/lib/python3.6/site-packages/channels/routing.py:61:__call__
]
WebSocket DISCONNECT /ws/chat/lobby/ [127.0.0.1:34724]
I couldn't find a duplicate of this question on stackoverflow
Solution 1:[1]
problem could be in the asgi.py :
application = ProtocolTypeRouter({ "http": get_asgi_application(), "websocket": AuthMiddlewareStack( URLRouter( chat.routing.websocket_urlpatterns ) ), # Just HTTP for now. (We can add other protocols later.) })
Solution 2:[2]
Those using centos,My issue was with redis. My system had redis version 3 updating it to redis version 6 or above got my django channels working. Redis was breaking in the background. Hope it helps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user15307766 |
Solution 2 | Japh |