Hỏi về module Python pickle

I want to deserialize this value by pickle module
8003635f5f6d61696e5f5f0a546f6b656e0a7100298171017d7102580800000069735f61646d696e71038973622e

after decode this, I can use pickle.loads to deserialize this value.My code:

import pickle
import codecs

value = '8003635f5f6d61696e5f5f0a546f6b656e0a7100298171017d7102580800000069735f61646d696e71038973622e'
decoded= codecs.getdecoder("hex_codec")
result = decoded(value)
print(result[0])
print(pickle.loads(result[0]))
Traceback (most recent call last):
  File "C:/Users/Dell/PycharmProjects/pythonProject5/main.py", line 9, in <module>
    print(pickle.loads(result[0]))
AttributeError: Can't get attribute 'Token' on <module '__main__' from 'C:/Users/Dell/PycharmProjects/pythonProject5/main.py'>
b'\x80\x03c__main__\nToken\nq\x00)\x81q\x01}q\x02X\x08\x00\x00\x00is_adminq\x03\x89sb.'

please help me to fix this and I will apreciate that

Missed attribute Token for __main__
You can simply create a class called Token so that pickle can load data to it

4 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?