我正在尝试使用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'
我检查了最后一个文件,发现错误与types模块有关。行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文件完全相同,因此解释这一点的任何帮助都会有所帮助。
答案 0 :(得分:0)
我正在浏览其他StackOverflow问题,我在python脚本中发现了一个常见错误,其中一个命名错误的文件导致导入错误。我浏览了频道安装目录,找到了一个名为import matplotlib.pyplot as plt
summed.plot.bar()
plt.show()
的文件,并将其更改为types.py
,程序正常工作。谢谢你的帮助。