With Django sessions, there are some cases where the encoded session data stored in the database can not be decoded using django.contrib.sessions.models.Session‘s get_decoded method, i.e. it will always return an empty dictionary.
Is there any way to decode that data?
It relies on django.contrib.sessions.backends.base.SessionBase‘s decode method, which will return an empty dictionary if a calculated hash is different from an expected hash (it raises a SuspiciousOperation exception).
django.contrib.sessions.models.Session‘sget_decodedmethod relies ondjango.contrib.sessions.backends.base.SessionBase.decode, which will return an empty dictionary if a calculated hash is different from an expected hash (it raises aSuspiciousOperationexception), there is aValueErroror unpickling exceptions. It will catch all exceptions really, but those are the reasons the code can fail.So, wrapping all those code calls together except the hash checking part, you can get what you need. Below there is a function that will give you the decoded session data of a certain session object, provided that it exists.
source: https://gist.github.com/3982485,
based on source code from the Django project.