2016-11-27 60 views
0

我想使用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文件是完全相同的,所以任何帮助解释这将有所帮助。

+0

你可以做'打印(类型)'并显示结果吗? – knbk

+0

@knbk我发布了结果 – Superman

回答

0

我在浏览其他的StackOverflow问题,我发现了一个Python脚本中一个常见的错误,其中一个命名错误的文件导致了导入错误。我在通道安装目录中环顾四周,发现一个名为types.py的文件,并将其更改为typer.py,程序正常运行。谢谢您的帮助。