请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

更换电脑后原来正常的代码报错了

假期在家开发,连结远程服务器上,把代码下载到本地

前端报错:
WebSocket connection to ‘ws://116.62.xxx.89:8000/ws/notifications/?kevin’ failed: Error during WebSocket handshake: Unexpected response code: 500

后端:
WebSocket HANDSHAKING /ws/notifications/ [116.249.212.112:4842]
Exception inside application: ‘NoneType’ object is not subscriptable
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/channels/sessions.py”, line 179, in call
return await self.inner(receive, self.send)
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/channels/middleware.py”, line 40, in coroutine_call
await self.resolve_scope(scope)
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/channels/auth.py”, line 166, in resolve_scope
scope[“user”]._wrapped = await get_user(scope)
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/asgiref/sync.py”, line 79, in call
return await asyncio.wait_for(future, timeout=None)
File “/usr/local/python3/lib/python3.7/asyncio/tasks.py”, line 388, in wait_for
return await fut
File “/usr/local/python3/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/channels/db.py”, line 14, in thread_handler
return super().thread_handler(loop, *args, **kwargs)
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/asgiref/sync.py”, line 91, in thread_handler
raise e
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/asgiref/sync.py”, line 89, in thread_handler
self.func(*args, **kwargs)
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/channels/auth.py”, line 35, in get_user
user_id = _get_user_session_key(session)
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/channels/auth.py”, line 137, in _get_user_session_key
return get_user_model()._meta.pk.to_python(session[SESSION_KEY])
File “/root/.virtualenvs/jcompass/lib/python3.7/site-packages/django/utils/functional.py”, line 214, in inner
return func(self._wrapped, *args)
‘NoneType’ object is not subscriptable
WebSocket DISCONNECT /ws/notifications/ [116.249.212.112:4842]
都不是我写的代码,而且这部分是异步的打断点也不好使。

我跟踪代码进去后发现:
是scope中一个叫session的变量为空导致的,不知道为什么,请老师指教…
图片描述

正在回答

1回答

是在websocket连接建立的过程中报错了吗?看到session为空,用户是否可以正常登陆?

1 回复 有任何疑惑可以回复我~
  • 提问者 李嘉图principal #1
    对的 建立连接过程中报错。 用户登陆正常,vuex中能看到token等信息
    回复 有任何疑惑可以回复我~ 2020-01-21 14:40:21
  • 提问者 李嘉图principal #2
    已解决,用的是token认证,结果调用了channel的AuthMiddlewareStack认证
    回复 有任何疑惑可以回复我~ 2020-01-23 23:32:42
  • 提问者 李嘉图principal #3
    非常感谢!
    回复 有任何疑惑可以回复我~ 2020-02-15 23:21:30
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信