Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket Handshaking Error in Python Django

I am getting issue with websocket connection as it is getting closed due to handshake error. The error message is as below:

WebSocket HANDSHAKING /ws/polData/ [127.0.0.1:59304]
Exception inside application: object.__init__() takes exactly one argument (the instance to initialize)
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/channels/routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "/usr/lib/python3.7/site-packages/channels/sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "/usr/lib/python3.7/site-packages/channels/sessions.py", line 172, in __call__
    return await self.inner(self.scope, receive, self.send)
  File "/usr/lib/python3.7/site-packages/channels/auth.py", line 181, in __call__
    return await super().__call__(scope, receive, send)
  File "/usr/lib/python3.7/site-packages/channels/middleware.py", line 26, in __call__
    return await self.inner(scope, receive, send)
  File "/usr/lib/python3.7/site-packages/channels/routing.py", line 160, in __call__
    send,
  File "/usr/local/lib/python3.7/dist-packages/asgiref/compatibility.py", line 33, in new_application
    instance = application(scope)
  File "/usr/lib/python3.7/site-packages/channels/generic/websocket.py", line 159, in __init__
    super().__init__(*args, **kwargs)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
WebSocket DISCONNECT /ws/polData/ [127.0.0.1:59304]\
like image 745
Sumedh Kharode Avatar asked Nov 01 '20 19:11

Sumedh Kharode


1 Answers

Check your routing.py in app,

under websocket_urlpatterns, on repath you may have missed .as_asgi()

eg:-

websocket_urlpatterns = [

    re_path(r'ws/chat/(?P<room_name>\w+)/$', consumers.ChatConsumer.as_asgi()),
]
like image 133
Shaheen Hyder Avatar answered Sep 19 '22 18:09

Shaheen Hyder