【发布时间】:2016-10-24 20:06:15
【问题描述】:
我正在使用PyJWT 在 Python 中生成和验证 JWT。运行pypy3 v2.4。
只需尝试 encode 和 decode 一个类似于 GitHub 存储库中示例的 JWT。解码时出现以下错误:
decoded = jwt.decode(encoded, secret, algorithm='HS256')
File "/usr/local/site-packages/jwt/api_jwt.py", line 64, in decode
options, **kwargs)
File "/usr/local/site-packages/jwt/api_jws.py", line 115, in decode
key, algorithms)
File "/usr/local/site-packages/jwt/api_jws.py", line 177, in _verify_signature
if not alg_obj.verify(signing_input, key, signature):
File "/usr/local/site-packages/jwt/algorithms.py", line 138, in verify
return constant_time_compare(sig, self.sign(msg, key))
File "/usr/local/site-packages/jwt/compat.py", line 50, in constant_time_compare
result |= ord(x) ^ ord(y)
TypeError: ord() expected string of length 1, but int found
很明显错误是从模块代码内部产生的。
知道是什么导致了这个错误吗?
谢谢
【问题讨论】:
-
“编码”和“秘密”变量的类型是什么?看起来它正在尝试从整数列表而不是字符列表中获取 ASCII 代码
-
“编码”是
bytes,“秘密”是str。这是“编码”的值:b'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'