问题描述
在 django_session中
表 session_data是
存储是使用python的泡菜模块先腌再带codeD用base64通过使用python的BASE64模块。
我得到了去codeD腌session_data是。
从表django_session中session_data是:
<$p$p><$c$c>gAJ9cQEoVQ9fc2Vzc2lvbl9leHBpcnlxAksAVRJfYXV0aF91c2VyX2JhY2tlbmRxA1UpZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbmRxBFUNX2F1dGhfdXNlcl9pZHEFigECdS5iZmUwOWExOWI0YTZkN2M0NDc2MWVjZjQ5ZDU0YjNhZA==由base64.de code(session_data是)进行解码后:
\\x80\\x02}q\\x01(U\\x0f_session_expiryq\\x02K\\x00U\\x12_auth_user_backendq\\x03U)django.contrib.auth.backends.ModelBackendq\\x04U\\r_auth_user_idq\\x05\\x8a\\x01\\x02u.bfe09a19b4a6d7c44761ecf49d54b3ad
我想找出 auth_user_id
从 auth_user_idq \\ X05 \\ x8a \\ X01 \\ x02u
。请帮我这样做。
我有麻烦与保罗的方法(见我对他的回答评论),所以我结束了使用这种方法从的:
从django.contrib.sessions.models导入会话
从django.contrib.auth.models导入用户session_key可以='8cae76c505f15432b48c8292a7dd0e54会话= Session.objects.get(session_key可以= session_key可以)
UID = session.get_de codeD()得到('_ auth_user_id')
用户= User.objects.get(PK = UID)打印user.username,user.get_full_name(),user.email
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 module of python.
I got the decoded pickled session_data.
session_data from django_session table:
gAJ9cQEoVQ9fc2Vzc2lvbl9leHBpcnlxAksAVRJfYXV0aF91c2VyX2JhY2tlbmRxA1UpZGphbmdvLmNvbnRyaWIuYXV0aC5iYWNrZW5kcy5Nb2RlbEJhY2tlbmRxBFUNX2F1dGhfdXNlcl9pZHEFigECdS5iZmUwOWExOWI0YTZkN2M0NDc2MWVjZjQ5ZDU0YjNhZA==
after decoding it by base64.decode(session_data):
\x80\x02}q\x01(U\x0f_session_expiryq\x02K\x00U\x12_auth_user_backendq\x03U)django.contrib.auth.backends.ModelBackendq\x04U\r_auth_user_idq\x05\x8a\x01\x02u.bfe09a19b4a6d7c44761ecf49d54b3ad
I want to find out auth_user_id
from auth_user_idq\x05\x8a\x01\x02u
. Please help me to do so.
I had trouble with Paulo's method (see my comment on his answer), so I ended up using this method from a scottbarnham.com blog post:
from django.contrib.sessions.models import Session
from django.contrib.auth.models import User
session_key = '8cae76c505f15432b48c8292a7dd0e54'
session = Session.objects.get(session_key=session_key)
uid = session.get_decoded().get('_auth_user_id')
user = User.objects.get(pk=uid)
print user.username, user.get_full_name(), user.email
这篇关于如何从表django_session中找到session_data是用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!