TypeError: AsyncConsumer.__call__() отсутствует 1 обязательный позиционный аргумент: 'send
Я использую каналы в качестве WebSocket и redis в качестве хранилища для создания приложения чата в Django.Чтобы выполнить соединение между websocketconsumer с файлом asgi. Я пытаюсь запустить сервер django на windows, но получаю следующую ошибку, помогите мне.
Ошибка
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
"""
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
<
Вернуться на верх
ws_patterns = [
path('ws/test/',TestConsumer)
]
к :
ws_patterns = [
path('ws/test/',TestConsumer.as_asgi())
]