有一个REST客户机向服务器发出HTTP请求。REST客户端发送包含报头的请求。
Authorization=Bearer someValidBase64现在我在Python3.8,Flask1.1.1,PyJWT==1.7.1中有了一个服务器应用程序。
@app.route(my_rest_end_point)
def get_service_payments():
authorization_header = request.headers.get('Authorization')
# It prints correctly: Bearer someValidBase64
print("Authorization header:\n" + authorization_header)
# Details from that header
user_permissions = jwt.decode(authorization_header)它失败了
File "/usr/local/lib/python3.7/site-packages/jwt/api_jws.py", line 188, in _load
raise DecodeError('Invalid header padding')
jwt.exceptions.DecodeError: Invalid header padding我试过的
authorization_header = request.headers.get('Authorization')
print("Authorization header:\n" + authorization_header)
cleared_header = authorization_header[7:]
print("cleared_header:\n" + cleared_header)
user_permissions = jwt.decode(cleared_header)它会打印出来
Authorization header:
Bearer someValidBase64
cleared_header:
someValidBase64它再次失败,因为令牌本身有一些ValidBase64的结构。
发布于 2020-01-22 15:51:38
问题是authorization_header由值"Bearer someValidBase64"组成。现在,当您试图解码这个错误时,您将面临这个错误,因为前缀"Bearer“是附加到它的。
确保您只将字符串的base64部分存储在没有前缀的authorization_header中,以便您能够成功地解码它。
更新:
据我所知,authorization_header由一个JWT令牌组成,由于您试图解码一个JWT令牌,如果您在此之外的任何格式中找到它,请确保您的authorization_header为xxxxx.yyyyy.zzzzz格式,确保只提取该JWT令牌的此格式。
https://stackoverflow.com/questions/59862509
复制相似问题