-1

When calling join_room() the following exception is fired:

AttributeError: 'Request' object has no attribute 'sid'

Please help find the reason.

here is the stack:

    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'
  • Which tutorial are you following? I believe from some github repo. Right? Please share link – Nabin Sep 27 '17 at 01:42

1 Answers1

1

The join_room() function from Flask-SocketIO is context based. It only works when you invoke it from inside a Socket.IO event handler.

In the stack trace you copied in your question the call appears to have been made from a regular HTTP route, which does not have enough information to identify the Socket.IO session.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152