Answer the question
In order to leave comments, you need to log in
How to connect to a socket in Django Channels?
When connecting to a socket, it gives the following error:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
November 03, 2020 - 07:02:03
Django version 3.1.3, using settings 'my_chat.settings'
Starting ASGI/Channels version 3.0.0 development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
WebSocket HANDSHAKING /ws/chat/ [127.0.0.1:43390]
Exception inside application: object.__init__() takes exactly one argument (the instance to initialize)
Traceback (most recent call last):
File "/home/sus/Desktop/test/env/lib/python3.8/site-packages/channels/routing.py", line 71, in __call__
return await application(scope, receive, send)
File "/home/sus/Desktop/test/env/lib/python3.8/site-packages/channels/routing.py", line 150, in __call__
return await application(
File "/home/sus/Desktop/test/env/lib/python3.8/site-packages/asgiref/compatibility.py", line 33, in new_application
instance = application(scope)
File "/home/sus/Desktop/test/env/lib/python3.8/site-packages/channels/generic/websocket.py", line 23, in __init__
super().__init__(*args, **kwargs)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
WebSocket DISCONNECT /ws/chat/ [127.0.0.1:43390]
Answer the question
In order to leave comments, you need to log in
I found out that this is due to updating channels to version 3.0.
Now in routing you need to additionally use the method as_asgi()
url(r'^ws/chat/$', ChatConsumer.as_asgi()),
Instead of
url(r'^ws/chat/$', ChatConsumer),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question