' WebSocketProtocol'对象没有属性' application_queue'错误Django频道

时间:2018-05-02 10:16:11

标签: django websocket django-channels

在我的Django项目中,我想使用channels创建一个聊天应用程序。但是当我按照本教程时: https://channels.readthedocs.io/en/stable/tutorial/part_2.html,我遇到连接后websocket自动断开连接的问题:

 Exception in callback AsyncioSelectorReactor.callLater.<locals>.run()
at
 C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\asyncioreact
 or.py:287 handle: <TimerHandle when=19405.993
 AsyncioSelectorReactor.callLater.<locals>.run() at
 C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\interne
 t\asyncioreactor.py:287> Traceback (most recent call last):   File
 "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\events.py",
 line 145, in _run
     self._callback(*self._args)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\asyncioreactor.py",
 line 290, in run
     f(*args, **kwargs)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\twisted\internet\tcp.py",
 line 289, in connectionLost
     protocol.connectionLost(reason)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\twisted\websocket.py",
 line 128, in connectionLost
     self._connectionLost(reason)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\websocket\protocol.py",
 line 2467, in _connectionLost
     WebSocketProtocol._connectionLost(self, reason)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\websocket\protocol.py",
 line 1096, in _connectionLost
     self._onClose(self.wasClean, WebSocketProtocol.CLOSE_STATUS_CODE_ABNORMAL_CLOSE, "connection was
 closed uncleanly (%s)" % self.wasNotCleanReason)   File
 "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\autobahn\twisted\websocket.py",
 line 171, in _onClose
     self.onClose(wasClean, code, reason)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\daphne\ws_protocol.py",
 line 146, in onClose
     self.application_queue.put_nowait({ AttributeError: 'WebSocketProtocol' object has no attribute 'application_queue'

3 个答案:

答案 0 :(得分:1)

迁移为我解决了

python manage.py migrate

答案 1 :(得分:0)

在此错误之上应该是路径列表,并且在路径的顶部是真正的错误。就我而言,这是路由网址。

答案 2 :(得分:0)

只是为每个面对它的人澄清这个错误,同时关注我的频道教程,错误在我的路径中

  

2018-05-17 15:55:36,382 - ERROR - ws_protocol - [失败实例:   回溯::找不到路径的路径   &#39; WS /的聊天 / ME /&#39;

你可以在stacktrace

之上找到它

我定义的无效网址格式&#34; buzz&#34;因为我喜欢改变一切。本质上它的工作方式与django url模式相同,因此只需要确保您的路由结构与您指定的匹配。

websocket_urlpatterns = [
    url(r'^ws/buzz/(?P<room_name>[^/]+)/$', consumers.ChatConsumer),
]

在我的情况下,路径路径与我的websocket模式不匹配 我必须更新路线路径才能正确 - &gt;通过将我的websocket_urlpatterns改回聊天

websocket_urlpatterns = [
    url(r'^ws/chat/(?P<room_name>[^/]+)/$', consumers.ChatConsumer),
]

因此系统可以解决我的问题。希望它可以帮助将来遇到这种情况的人们。祝好运。 P.T。