我正在尝试解码一个简单的jwt这个
eyJraWQiOiJlWGF1bm1MIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLm1kbC5lbnRlcmN5IiwiZXhwIjoxNjI3MzgyMTI3LCJpYXQiOjE2MjcyOTU3MjcsInN1YiI6IjAwMTUxMC5hNjQ0MzcyOWE3OTU0ZmQyYTE2NjcyN2NjODY0ZDUyZi4wODI4IiwiY19oYXNoIjoiVl9yUG1Db1Vab0lmejlJQW9WcEFNZyIsImVtYWlsIjoiZnJlZGVyaWNrLm1kbEBnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJhdXRoX3RpbWUiOjE2MjcyOTU3MjcsIm5vbmNlX3N1cHBvcnRlZCI6dHJ1ZX0.DDc3G6jJbsLXYX_F3GQ851mEukVDAMvySDPWwWfsmQOmi8w_ItCUaMwSMp0djzzFy3dLpF2cMp67n
我在下面的链接中成功地解码了它,您可以在这里查看它https://jwt.io/
但是当我尝试使用python时,我没有成功
import jwt
def main(args):
encoded_jwt = "eyJraWQiOiJlWGF1bm1MIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLm1kbC5lbnRlcmN5IiwiZXhwIjoxNjI3MzgyMTI3LCJpYXQiOjE2MjcyOTU3MjcsInN1YiI6IjAwMTUxMC5hNjQ0MzcyOWE3OTU0ZmQyYTE2NjcyN2NjODY0ZDUyZi4wODI4IiwiY19oYXNoIjoiVl9yUG1Db1Vab0lmejlJQW9WcEFNZyIsImVtYWlsIjoiZnJlZGVyaWNrLm1kbEBnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJhdXRoX3RpbWUiOjE2MjcyOTU3MjcsIm5vbmNlX3N1cHBvcnRlZCI6dHJ1ZX0.DDc3G6jJbsLXYX_F3GQ851mEukVDAMvySDPWwWfsmQOmi8w_ItCUaMwSMp0djzzFy3dLpF2cMp67n"
val=jwt.decode(encoded_jwt, options={"verify_signature": False})
print(val)
return;
if __name__ == '__main__':
main(0)
这是我得到的错误
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\jwt\venv\lib\site-packages\jwt\api_jws.py", line 211, in _load
signature = base64url_decode(crypto_segment)
File "C:\Users\User\PycharmProjects\jwt\venv\lib\site-packages\jwt\utils.py", line 33, in base64url_decode
return base64.urlsafe_b64decode(input)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\base64.py", line 133, in urlsafe_b64decode
return b64decode(s)
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: number of data characters (77) cannot be 1 more than a multiple of 4
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\User\PycharmProjects\jwt\jwts.py", line 13, in <module>
main(3)
File "C:\Users\User\PycharmProjects\jwt\jwts.py", line 8, in main
val=jwt.decode(encoded_jwt, options={"verify_signature": False})
File "C:\Users\User\PycharmProjects\jwt\venv\lib\site-packages\jwt\api_jwt.py", line 119, in decode
decoded = self.decode_complete(jwt, key, algorithms, options,**kwargs)
File "C:\Users\User\PycharmProjects\jwt\venv\lib\site-packages\jwt\api_jwt.py", line 90, in decode_complete
decoded = api_jws.decode_complete(
File "C:\Users\User\PycharmProjects\jwt\venv\lib\site-packages\jwt\api_jws.py", line 146, in decode_complete
payload, signing_input, header, signature = self._load(jwt)
File "C:\Users\User\PycharmProjects\jwt\venv\lib\site-packages\jwt\api_jws.py", line 213, in _load
raise DecodeError("Invalid crypto padding") from err
jwt.exceptions.DecodeError: Invalid crypto padding
暂无答案!
目前还没有任何答案,快来回答吧!