python - 是否将其设为静态方法....这是个问题
问题描述
我遇到了模型脚本处理令牌验证的这段代码:
def encode_auth_token(self, user_id):
try:
payload = {
'exp': datetime.datetime.utcnow() + datetime.timedelta(
days=current_app.config.get('TOKEN_EXPIRATION_DAYS'), \
seconds=current_app.config.get('TOKEN_EXPIRATION_SECONDS')),
'iat': datetime.datetime.utcnow(),
'sub': user_id
}
return jwt.encode(payload, current_app.config.get('SECRET_KEY'), algorithm='HS256')
except Exception as e:
return e
@staticmethod
def decode_auth_token(token):
try:
return jwt.decode(token, current_app.config.get('SECRET_KEY'))
except jwt.ExpiredSignatureError:
return 'Signature expired. Please log in again.'
except jwt.InvalidTokenError:
return 'Invalid token. Please log in again.'
我对这段代码的问题是为什么decode_auth_token
方法需要是静态方法encode_auth_token
而不需要?
解决方案
推荐阅读
- python - 如何在 Conv1D() 函数中使用“input_shape”?
- javascript - 如何在节点的sqlite数据库中插入一个Js数组
- python - Discord.py 破坏静音命令
- sql - 如何总结不同的重叠时间范围?
- python - 如何使这个函数递归?
- java - 如何在这个平方根程序的打印/数学部分使用计数器控制的迭代
- c# - C# FtpWebRequest 下载的 FTP 文件为空
- python - 提高 pandas 和 dask 聚合自定义函数速度
- python-3.x - 'NoneType 对象没有属性'发送'
- python - 当for循环不起作用时如何留下空单元格?