调用join_room()时会触发以下异常:
AttributeError: 'Request' object has no attribute 'sid'
请帮助找到原因。
这是堆栈:
127.0.0.1 - - [2017-09-26 19:56:31] "GET /socket.io/?EIO=3&transport=polling&t=Lx0dkBs HTTP/1.1" 200 345 0.001772
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "server.py", line 26, in index
join_room(game_id)
File "/usr/local/lib/python2.7/site-packages/flask_socketio/__init__.py", line 756, in join_room
sid = sid or flask.request.sid
File "/usr/local/lib/python2.7/site-packages/werkzeug/local.py", line 343, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'sid'
答案 0 :(得分:0)
Flask-SocketIO的join_room()
功能是基于上下文的。它仅在从Socket.IO事件处理程序中调用它时才有效。
在您在问题中复制的堆栈跟踪中,调用似乎是从常规HTTP路由进行的,该路由没有足够的信息来识别Socket.IO会话。