2016-06-22 46 views
0

我正在使用PyJWT在Python中生成和验证JWT。运行pypy3 v2.4pyjwt在解码时产生错误

只需尝试encodedecode一个类似于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 

很明显,错误是从模块代码中产生的。

任何想法是什么导致此错误?

感谢

+0

什么是“编码”和“秘密”变量的类型的int?它看起来像试图从int列表中获取ASCII代码而不是字符列表 –

+0

“encoded”是“bytes”,“secret”是“str”。 这是“encoded”的值:'b'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'' – Sincere

回答

0

PyJWT不支持蟒蛇3.2,pyJWT使用hmac.compare_digest来验证这是在Python 3.3添加签名,它得到解决此通过重新实现compare_digest为Python 2但重新实现犯规支持蟒蛇3.2自索引到一个字节对象返回在python 2的字符和在python 3.

source