Error using flask session data in SocketIO namespace Error using flask session data in SocketIO namespace flask flask

Error using flask session data in SocketIO namespace


Unfortunately this cannot be done, because namespaces aren't dynamic, you have to use a static string as a namespace.

The idea of the namespace in SocketIO is not to add information about the connection, but to allow the client to open more than one individual channel with the server. Namespaces allow the SocketIO protocol to multiplex all these channels into a single physical connection.

What you want to do is to provide an input argument of the connection into the server. For that, just add the value to your payload:

@socketio.on('connect', namespace='/chat')def test_connect():    userid = session['userId']    # ...