Problem decoding token
See original GitHub issueHello, thanks for making pyjwt!
I’ve been trying to use it in my Django application, however, something weird is happening: I can’t decode the token!
This is how I’m creating the token
token = jwt.encode({
'user_id': user.id
}, key='secret', algorithm='HS256')
And creating a token with user_id: 1
gives me this token b'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.J_RIIkoOLNXtd5IZcEwaBDGKGA3VnnYmuXnmhsmDEOs'
, however it says invalid signature in https://jwt.io/ for some reason.
Trying to decode my token in the server throws this error:
Traceback (most recent call last):
File "/home/andres/venv/zyru/lib/python3.6/site-packages/jwt/api_jws.py", line 170, in _load
header_data = base64url_decode(header_segment)
File "/home/andres/venv/zyru/lib/python3.6/site-packages/jwt/utils.py", line 42, in base64url_decode
return base64.urlsafe_b64decode(input)
File "/home/andres/venv/zyru/lib/python3.6/base64.py", line 133, in urlsafe_b64decode
return b64decode(s)
File "/home/andres/venv/zyru/lib/python3.6/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/andres/Code/Python/zyru-api/members/schema.py", line 41, in get_user
decoded = jwt.decode(token, 'secret')
File "/home/andres/venv/zyru/lib/python3.6/site-packages/jwt/api_jwt.py", line 70, in decode
payload, signing_input, header, signature = self._load(jwt)
File "/home/andres/venv/zyru/lib/python3.6/site-packages/jwt/api_jws.py", line 172, in _load
raise DecodeError('Invalid header padding')
jwt.exceptions.DecodeError: Invalid header padding
Why is the exception happening?
Thanks a lot!
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Decode JWT runtime error troubleshooting | Apigee Edge
This error occurs if the JSON Web Token (JWT) specified in the <Source> element of the Decode JWT policy is malformed, invalid or...
Read more >Decode JWT runtime error troubleshooting | Apigee X
This error occurs if the JSON Web Token (JWT) specified in the <Source> element of the Decode JWT policy is malformed, invalid or...
Read more >Token decode error · Issue #61 · auth0/jwt-decode - GitHub
Some of our users have randomly been getting errors like and Invalid token specified: e is undefined thrown when their token is decoded....
Read more >Problem decoding JWT token with public key from Gravitee in ...
I'm trying to decode a Gravitee JWT ...
Read more >Built in token service unable to decode token - Opster
This guide will help you check for common problems that cause the log ” Built in token service unable to decode token ”...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This isn’t right:
You want to create the token like such:
and decode it like:
Try decoding the token to utf-8:
In jwt.io, you need to get rid of the
b''
part of the string. That indicates that it is a byte string, and is not actually part of the token.