Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: AsyncConsumer.__call__() missing 1 required positional argument: 'send

Well I am using channels as WebSocket and redis as storage to build chat application in Django.so to accomplish connection between the websocketconsumer with asgi file. I am trying to run the django server on windows but I am getting the following error, help me.

Error

Exception inside application: AsyncConsumer.__call__() missing 1 required positional argument: 'send'
Traceback (most recent call last):
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python310\lib\site-packages\channels\staticfiles.py", line 44, in __call__
    return await self.application(scope, receive, send)
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python310\lib\site-packages\channels\routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python310\lib\site-packages\channels\routing.py", line 150, in __call__
    return await application(
  File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python310\lib\site-packages\asgiref\compatibility.py", line 34, in new_application
    return await instance(receive, send)
TypeError: AsyncConsumer.__call__() missing 1 required positional argument: 'send'
WebSocket DISCONNECT /ws/test/ [127.0.0.1:59461]

asgi.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"""
ASGI config for chatapp project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter,URLRouter
from django.urls import path
from home.consumers import *

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatapp.settings')

application = get_asgi_application()
ws_patterns = [
    path('ws/test/',TestConsumer)
]

application = ProtocolTypeRouter({
    'websocket' : URLRouter(ws_patterns)
})

consumers.py

from channels.generic.websocket import WebsocketConsumer
from asgiref.sync import async_to_sync
import json
class TestConsumer ( WebsocketConsumer ) :
    def connect(self):
        self.room_name = "test_consumer" 
        self.room_group_name="test_consumer_group"
        async_to_sync(self.channel_layer.group_add)(
            self.room_name,self.room_group_name
        )
        self.accept()
        self.send(text_data=json.dumps({'status':'connected'}))
    def receive(self):
        pass

    def disconnect(self):
        pass

>Solution :

change :

ws_patterns = [
    path('ws/test/',TestConsumer)
]

to :

ws_patterns = [
    path('ws/test/',TestConsumer.as_asgi())
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading