我正在使用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很明显,这个错误是从模块代码内部产生的。
你知道是什么导致了这个错误吗?
谢谢
发布于 2017-02-22 03:16:54
PyJWT不支持Python3.2,pyJWT使用hmac.compare_digest来验证Python3.3中添加的签名,它通过为Python2重新实现compare_digest来绕过这个问题,但是重新实现不支持Python3.2,因为索引到字节对象会返回Python2中的字符和Python3中的整数。
https://stackoverflow.com/questions/37975523
复制相似问题