flask-session icon indicating copy to clipboard operation
flask-session copied to clipboard

Any way to retrieve data from filesystem session files?

Open adelyafatykhova opened this issue 6 years ago • 2 comments

I'm using filesystem type and want to be able to access the data in the session file in a way that can be parsed or human readable.

These files look something like this now:

Systemic DesignîåNeutralîåUser Innovation / User DesignîåNeutralîå
Value Proposition CanvasîåAgreeîåWaterfall / Stage GateîåNeutralîuueuht}î(hås5îhåApplicationîhåÇ
This section is about the context.îh]î(}î(hj!��håq8îh å	frequencyîh!å;How frequently or infrequently do you use this method?îh"hh#å

Is there any way to be able to retrieve the data from such files?

For context, I had an instance where for my web app writing to the database was briefly not working - but the data I need was also being saved in the session.

adelyafatykhova avatar Jul 18 '19 23:07 adelyafatykhova

You may be able to decode the files with pickle.load from the standard library. flask-session users werkzeug.contrib.cache for the implementation of filesystem caching, which is based on pickle.

Example:

import pickle
with open("<filename>", "rb") as e:
    time = pickle.load(e)
    data = pickle.load(e)

Varbin avatar Aug 17 '19 11:08 Varbin

Pickle should work. You can use also use whatever serializer is currently configured with app.session_interface.serializer (but default value for this is the pickle module so it's the same thing)

In my code I'm also using want_bytes imported from itsdangerous: app.session_interface.serializer.loads(want_bytes(sessiondata))

tassaron avatar Jan 01 '21 13:01 tassaron