state_str = str(state)[2:-1].encode()
import base64
#字符串编码为字节流
str = 'hello world'.encode(encoding='utf-8') # b'hello world'
state = base64.b64encode(str) # 加密 b'aGVsbG8gd29ybGQ='
state_byte = str(state)[2:-1].encode()
decode = base64.b64decode(state) # 解密 b'hello world'
decode = decode.decode(encoding='utf-8') # hello world