6

Good Morning,

I have been having some trouble and I am hoping some one will be able to help me out a bit here. What I am trying to do is access the Flask Session within a Gevent Socket-IO Name space.

I have tried to use beaker as a middle ware client and I am still unable to access & update the session information from within a socket-io name space.

I am pretty new to all of this so any help would be greatly appreciated .

1 Answer 1

3

With the default Flask session, it seems possible to share (with read-only access) the session data at the time the namespace is initialized.

session_dict=dict(session)
socketio_manage(request.environ, {'/news': NewsNamespace}, request=session_dict)

session_dict is then accessible as self.request in the namespace. This is a hack, but Flask/werkzeug sessions don't seem to work outside the request context anyway.

I put a session ID (randomly-generated uuid) in the Flask session. Then, both Flask views and the namespace both know the session ID, and both can read/write data in a server-side session in Redis or some other datastore, with session ID as the key.

This is just the solution I'm using for sharing sessions between Flask and gevent-socketio; I haven't tried Beaker and am not sure what specific issues you've had in using that, or if there's a better solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.