尝试使用 devserver 提供静态文件时出现 Django 通道错误

Django channels error when attempting to serve static files with devserver

我将我的项目移到另一个环境中,在安装依赖项并尝试 运行 manage.py 运行 服务器 - devserver 请求静态文件时出现以下错误。 坦率地说,我完全迷失了这个错误,有人知道这是怎么回事吗?

    HTTP GET /static/admin/css/responsive.css 500 [0.21, 127.0.0.1:59982]
Exception inside application: async_to_sync can only be applied to async functions.
Traceback (most recent call last):
  File "/home/maxehleny/.local/share/virtualenvs/mysite-EdbyOLs2/lib/python3.6/site-packages/channels/staticfiles.py", line 41, in __call__
    dict(scope, static_base_url=self.base_url), receive, send
  File "/home/maxehleny/.local/share/virtualenvs/mysite-EdbyOLs2/lib/python3.6/site-packages/channels/staticfiles.py", line 56, in __call__
    return await super().__call__(scope, receive, send)
  File "/home/maxehleny/.local/share/virtualenvs/mysite-EdbyOLs2/lib/python3.6/site-packages/channels/http.py", line 198, in __call__
    await self.handle(scope, async_to_sync(send), body_stream)
  File "/home/maxehleny/.local/share/virtualenvs/mysite-EdbyOLs2/lib/python3.6/site-packages/asgiref/sync.py", line 105, in __init__
    raise TypeError("async_to_sync can only be applied to async functions.")
TypeError: async_to_sync can only be applied to async functions.

我几乎不知道问题出在哪里,因为我看不出这与我自己的代码有什么关系。如果我注释掉频道,其他一切正常。

Edit2 根据 ladruas 的回答降级到 asgiref==3.2.10 也对我有用。

两者之间似乎不兼容 频道==3.0.3 asgiref==3.3.10

我将 asgiref==3.2.10 添加到我的 requirements.txt 文件中,它似乎已经解决了问题。