pallets-eco / flask-session

Server side session extension for Flask
https://flask-session.readthedocs.io
BSD 3-Clause "New" or "Revised" License
501 stars 239 forks source link

Any way to retrieve data from filesystem session files? #104

Closed adelyafatykhova closed 1 year ago

adelyafatykhova commented 5 years ago

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.

Varbin commented 5 years ago

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)
tassaron commented 3 years ago

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))