2016-11-27 56 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,程序正常運行。謝謝您的幫助。