我想使用django频道和asgi来运行简单的聊天服务器。我安装了频道和daphne,但是当我尝试运行开发服务器时,出现以下错误。Django python无法从模块类型导入FunctionType
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'>
EDIT 2 我开始了另Django项目与渠道,克隆从GitHub存储库。当我安装依赖关系后运行开发服务器时,它完美运行。 channels utils文件是完全相同的,所以任何帮助解释这将有所帮助。
你可以做'打印(类型)'并显示结果吗? – knbk
@knbk我发布了结果 – Superman