【问题标题】:TypeError: __call__() missing 1 required positional argument: 'send' Django类型错误:__call__() 缺少 1 个必需的位置参数:“发送”Django
【发布时间】:2021-09-12 14:25:51
【问题描述】:

当我通过 gunicorn 运行项目时(命令:gunicorn --bind :8000 myproject.asgi:application),我收到此错误。

错误

Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 136, in handle
    self.handle_request(listener, req, client, addr)
  File "/venv/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
TypeError: __call__() missing 1 required positional argument: 'send'

asgi.py

import os
from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings.base')
django_asgi_app = get_asgi_application()

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter

from channels.security.websocket import AllowedHostsOriginValidator
from chats import routing

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": AllowedHostsOriginValidator(
        AuthMiddlewareStack(
            URLRouter(
                routing.websocket_urlpatterns
            )
        )
    ),
})

chats.routing.py

from django.urls import re_path

from . import consumers

websocket_urlpatterns = [
    re_path(r'ws/messages/(?P<username>[-:\w]+)/$', consumers.ChatConsumer.as_asgi()),
]

【问题讨论】:

标签: python django gunicorn django-channels asgi


【解决方案1】:

There is an issue on github similar to your problem

答案:您可能错过了routing.py 中的as_asgi()

【讨论】:

  • 但是您使用的是consumers.ChatConsumer.as_asgi(),所以可能是语法错误,或者您可以在那里提出另一个问题?
  • 我已经通过在路径后添加.as_asgi() 解决了我的问题。不知道是什么让您的问题没有得到解决。
猜你喜欢
  • 2022-06-22
  • 2020-12-05
  • 2022-11-10
  • 1970-01-01
  • 2022-01-11
  • 2022-01-10
  • 1970-01-01
  • 2018-09-12
相关资源
最近更新 更多