Ani*_*yan 5 python authorization flask jwt
所以我有一个简单的烧瓶应用程序。登录会创建一个令牌:
token = jwt.encode({'user': token_data}, app.config['SECRET_KEY']).decode('utf-8')
Run Code Online (Sandbox Code Playgroud)
中间件看起来像这样:
def token_required(f):
@wraps(f)
def decorated(*args, **kwargs):
data = request.headers['Authorization'].encode('ascii', 'ignore')
token = str.replace(str(data), 'Bearer ', '')
if not token:
return jsonify({'message': 'Token is missing'}), 401
data = jwt.decode(token, app.config['SECRET_KEY'], algorithms=['HS256'])['sub']
return f(*args, **kwargs)
return decorated
Run Code Online (Sandbox Code Playgroud)
然后我运行一个受保护的路由@token_required并得到错误。
jwt.exceptions.DecodeError: Invalid header padding
无法将另一个 utf-8 添加到中间件令牌,因为我无法将它用于str
我能做什么?
| 归档时间: |
|
| 查看次数: |
4806 次 |
| 最近记录: |