首页 > 其他 > 详细

itsdangerous 产生token

时间:2019-06-01 13:57:49      阅读:100      评论:0      收藏:0      [点我收藏+]

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)

# 异常处理:

 

itsdangerous 产生token

原文:https://www.cnblogs.com/skyxiuli/p/10958590.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!