Closed rickwierenga closed 2 years ago
Are you trying to send the session dictionary as a websocket message? You can only send text or bytes, maybe that is the problem?
It's automatically converted to its string representation, so that actually works fine. It is missing the index
key, however, while ws
is set to True. Visiting /session
afterwards shows index=True
, and no value for ws
.
@rickwierenga I don't understand what is the problem. Running your code, the websocket client displays the correct session data:
Connected to websocket
Received message from websocket
<FileSystemSession {'_permanent': True, 'index': True, 'ws': True}>
And the /session
endpoint as well:
{"_permanent":true,"index":true}
If you were expecting the ws
key to be seen by the /session
endpoint, that is incorrect. Flask saves the session when a route exits. Your WebSocket route runs a loop and never exits, so the session changes you make in this route will not be saved, unless you save them yourself.
Flask saves the session when a route exits.
Didn't know that, thanks for explaining.
First off, thanks for all of your amazing work.
I am looking to use sessions with flask-sock, and found your tutorial for socketio here. Unfortunately this does not work with this library (yet). I am willing to create a PR for this, but would appreciate a pointer on where to start.
Here's a minimal reproducible example:
Thanks again!