更换电脑后原来正常的代码报错了
来源:10-15 排错思路讲解与课后作业
李嘉图principal
2020-01-19
假期在家开发,连结远程服务器上,把代码下载到本地
前端报错:
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为空,用户是否可以正常登陆?
132020-02-15
相似问题