Django Channels/Daphne Internal Server Error "'dict' object is not callable"

时间:2018-03-25 21:11:52

标签: django channels daphne

I have received this Error when connecting to my site as it is running channels.

2018-03-25 20:59:19,049 - ERROR - http_protocol - Traceback (most recent call last):
  File "/home/.virtualenvs/blog/lib/python3.5/site-packages/daphne/http_protocol.py", line 158, in process
"server": self.server_addr,
  File "/home/.virtualenvs/blog/lib/python3.5/site-packages/daphne/server.py", line 184, in create_application
application_instance = self.application(scope=scope)
  File "/home/.virtualenvs/blog/lib/python3.5/site-packages/channels/staticfiles.py", line 42, in __call__
return self.application(scope)
TypeError: 'dict' object is not callable

I have no idea where to start decoding the error. The channels server managed to start with this

Starting ASGI/Channels development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
2018-03-25 20:57:45,400 - INFO - server - HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2018-03-25 20:57:45,400 - INFO - server - Configuring endpoint 
tcp:port=8000:interface=0.0.0.0
2018-03-25 20:57:45,401 - INFO - server - Listening on TCP address 0.0.0.0:8000

2 个答案:

答案 0 :(得分:1)

我遇到了类似的问题,导致daphne服务器在开发过程中崩溃。

File "C:\Users\sjsui\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers[base.py](base.py)", line 39, 
in load_middleware mw_instance = middleware(handler) 
TypeError: 'module' object is not callable

我意识到在从pip安装channel包时,我不小心在settings.MIDDLEWARE添加了一个错误的中间件:

enter image description here

删除此行django.middleware后,我能够再次启动开发服务器。

答案 1 :(得分:1)

不知道它是否仍然有用,但是对于其他人来说,我今天已经知道了。

在升级Django时配置新环境时,我使用

创建了一个asgi.py文件。
 application = 'whatever.module.application' 

在我的情况下,错误消息是“ str”对象不可调用。

因此,我做了一些思考(因为找不到此问题的直接答案,而且我几乎将其发布在堆栈上了);并认为应用程序变量必须是实际的路由器实例。

在我的情况下,我使用协议路由器,因为我需要websocket和普通的HTTP。早先查看代码,http_protocol.py在内部对其进行处理(“#BORING old HTTP”是其中的一条注释。大声笑。)

application = ProtocolTypeRouter({
    "websocket": urls.urlpatterns
}) 

,然后urls.urlpatterns可能包含以下内容:

urlpatterns = [
  url(r'^', include('cars.urls', namespace='cars')),
  url(r'^help/', include('help.urls', namespace='help'))
]

我猜你的问题是直接在上面的urlpatterns中使用类似的东西

...
application = []
...

信任可以帮助遇到相同问题的人。