Om Kashyap
Om Kashyap

Reputation: 308

Django channels error : TypeError: __call__() missing 1 required positional argument: 'send'

I am working on Django channels and Async application and I am totally new into it. I started seeing tutorials for that . When I ran django server , it works fine but when I load the page or try to connect with websocket king client for testing the server , it show the error ->


WebSocket HANDSHAKING /ws/game/roomname [127.0.0.1:51190]
Exception inside application: __call__() missing 1 required positional argument: 'send'
Traceback (most recent call last):
  File "C:\Users\user\anaconda3\lib\site-packages\channels\staticfiles.py", line 44, in __call__
    return await self.application(scope, receive, send)
  File "C:\Users\user\anaconda3\lib\site-packages\channels\routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "C:\Users\user\anaconda3\lib\site-packages\channels\sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "C:\Users\user\anaconda3\lib\site-packages\channels\sessions.py", line 263, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
  File "C:\Users\user\anaconda3\lib\site-packages\channels\auth.py", line 185, in __call__
    return await super().__call__(scope, receive, send)
  File "C:\Users\user\anaconda3\lib\site-packages\channels\middleware.py", line 26, in __call__
    return await self.inner(scope, receive, send)
  File "C:\Users\user\anaconda3\lib\site-packages\channels\routing.py", line 150, in __call__
    return await application(
  File "C:\Users\user\anaconda3\lib\site-packages\asgiref\compatibility.py", line 34, in new_application
    return await instance(receive, send)
TypeError: __call__() missing 1 required positional argument: 'send'
WebSocket DISCONNECT /ws/game/roomname [127.0.0.1:51190]

I am new into it and I am unable to solve the problem . Kindly help .

My project asgi.py

import os
from channels.routing import ProtocolTypeRouter , URLRouter 
from channels.auth import AuthMiddlewareStack
from home.consumers import GameRoom
from django.urls import path

from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tictac.settings')

application = get_asgi_application()

ws_pattern = [
    path("ws/game/<room_code>" , GameRoom)
]

application = ProtocolTypeRouter({
    "websocket" : AuthMiddlewareStack(URLRouter(
        ws_pattern
    ))
})

If possible please provide a detailed explanation to this so that I understand what is the error .

Upvotes: 3

Views: 2805

Answers (1)

sachin
sachin

Reputation: 56

Just change your

ws_pattern = [
    path("ws/game/<room_code>" , GameRoom)
]

With

ws_pattern = [
    path("ws/game/<room_code>" , GameRoom.as_asgi())
]

Upvotes: 4

Related Questions