how to find user id from session_data from django_session table?

前端 未结 6 1656
粉色の甜心
粉色の甜心 2020-12-28 15:24

In django_session table session_data is stored which is first pickled using pickle module of python and then encoded in base64 by using base64 modu

6条回答
  •  执笔经年
    2020-12-28 15:58

    I wanted to do this in pure Python with the latest version of DJango (2.05). This is what I did:

    >>> import base64
    >>> x = base64.b64decode('OWNkOGQxYjg4NzlkN2ZhOTc2NmU1ODY0NWMzZmQ4YjdhMzM4OTJhNjp7Im51bV92aXNpdHMiOjJ9')
    >>> print(x)
    b'9cd8d1b8879d7fa9766e58645c3fd8b7a33892a6:{"num_visits":2}'
    >>> import json
    >>> data = json.loads(x[41:])
    >>> print(data)
    {'num_visits': 2}
    

提交回复
热议问题