TypeError:AuthMiddlewareStack() 缺少 1 个必需的位置参数:'inner'

Posted

技术标签:

【中文标题】TypeError:AuthMiddlewareStack() 缺少 1 个必需的位置参数:\'inner\'【英文标题】:TypeError: AuthMiddlewareStack() missing 1 required positional argument: 'inner'TypeError:AuthMiddlewareStack() 缺少 1 个必需的位置参数:'inner' 【发布时间】:2021-03-11 00:25:50 【问题描述】:

您好,我正在尝试构建 ASGI 应用程序,但是 我收到此错误

File "/home/marwan/Desktop/Gowd/gowd_project/config/routing.py", line 8, in <module>
    AuthMiddlewareStack(
TypeError: AuthMiddlewareStack() missing 1 required positional argument: 'inner'

这是我的 routing.py 文件

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.urls import path

application = ProtocolTypeRouter(
    'websocket': AllowedHostsOriginValidator(
        AuthMiddlewareStack(
            # URLRouter([...]) # Empty for now because we don't have a consumer yet.
        )
    )
)

【问题讨论】:

【参考方案1】:

试试下面的代码

application = ProtocolTypeRouter(
    'websocket': AllowedHostsOriginValidator(
        AuthMiddlewareStack(
            URLRouter([])
        )
    ),
)

【讨论】:

以上是关于TypeError:AuthMiddlewareStack() 缺少 1 个必需的位置参数:'inner'的主要内容,如果未能解决你的问题,请参考以下文章