0
我正在使用PyJWT在Python中生成和驗證JWT。運行pypy3 v2.4。pyjwt在解碼時產生錯誤
只需嘗試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
很明顯,錯誤是從模塊代碼中產生的。
任何想法是什麼導致此錯誤?
感謝
什麼是「編碼」和「祕密」變量的類型的int?它看起來像試圖從int列表中獲取ASCII代碼而不是字符列表 –
「encoded」是「bytes」,「secret」是「str」。 這是「encoded」的值:'b'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'' – Sincere