import itsdangerous #产生token def create_token(data,expires_time=3600): salt = '!@#' t = itsdangerous.TimedJSONWebSignatureSerializer(salt,expires_in=expires_time) # 产生一个token res = t.dumps(data) token = res.decode() print("产生的token:\n",token) return token def check_token(token): t = itsdangerous.TimedJSONWebSignatureSerializer("!@#") # 产生一个token try: res = t.loads(token) except Exception as e: print(e) print("出错了,token失效") else: print("解析的token:\n",res) return res finally: print("finally---") data=create_token({"username": "niuhanyang"}) check_token(data) # 异常处理: