我正在尝试使用 django 频道和 asgi 来运行一个简单的聊天服务器。我安装了频道和 daphne,但是当我尝试运行开发服务器时,出现以下错误。
Unhandled exception in thread started by <function wrapper at 0x1062fdc80>
Traceback (most recent call last):
File "/Users/yash/code/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/yash/code/lib/python2.7/site-packages/channels/management/commands/runserver.py", line 63, in inner_run
"layer": self.channel_layer,
File "/Users/yash/code/lib/python2.7/site-packages/channels/asgi.py", line 86, in __str__
return "%s (%s)" % (self.alias, name_that_thing(self.channel_layer))
File "/Users/yash/code/lib/python2.7/site-packages/channels/utils.py", line 25, in name_that_thing
return name_that_thing(thing.__class__)
File "/Users/yash/code/lib/python2.7/site-packages/channels/utils.py", line 16, in name_that_thing
if hasattr(thing, "__class__") and not isinstance(thing, (types.FunctionType, types.MethodType)):
AttributeError: 'module' object has no attribute 'FunctionType'
我检查了最后一个文件,发现错误与类型模块有关。该行import types
工作正常,但是当脚本尝试调用types.FunctionType
它时会给出 AttributeError。当我在 shell 上导入脚本时,它按预期工作
任何帮助是极大的赞赏。:)
编辑
print(types)
输出:
<module 'types' from '/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/types.pyc'>
编辑 2 我用频道开始了另一个 django 项目,从 github 克隆了一个存储库。当我在安装依赖项后运行开发服务器时,它运行良好。通道 utils 文件完全相同,因此任何解释此问题的帮助都会有所帮助。