jwt.encode generating bytes instead of a string
See original GitHub issueThe documentation example seems to indicate the result of jwt.encode is a string. The actual result with Python 3.7.1 is bytes. If this is just a documentation issue i’m happy to submit a small PR.
Expected Result
>>> import jwt
>>> encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'
>>> jwt.decode(encoded, 'secret', algorithms=['HS256'])
{'some': 'payload'}
Actual Result
Python 3.7.1 (default, Dec 14 2018, 13:28:58)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import jwt
In [2]: encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
In [3]: encoded
Out[3]: b'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U'
System Information
{
"cryptography": {
"version": "2.4.2"
},
"implementation": {
"name": "CPython",
"version": "3.7.1"
},
"platform": {
"release": "18.2.0",
"system": "Darwin"
},
"pyjwt": {
"version": "1.7.1"
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:21
- Comments:12 (2 by maintainers)
Top Results From Across the Web
JWT is being converted from str to bytes on requests.post()
I am writing a Flask application in which I have a service that generates a JWT and passes this onto another service ...
Read more >Changelog — PyJWT 2.6.0 documentation
Tokens are returned as string instead of a byte string ... And the old v1.x syntax jwt.decode(token, verify=False) is now: jwt.decode(jwt=token, ...
Read more >Understanding JWT for apps - Atlassian Developer
The claims in a JWT are encoded as a JavaScript Object Notation (JSON) object that is used as the payload of a JSON...
Read more >How to Handle JWTs in Python - Auth0
Learn how to create, encode, parse, decode and verify your JWTs in Python using ... how to create JWTs in Python using the...
Read more >OAuth2 with Password (and hashing), Bearer with JWT tokens
We need to install python-jose to generate and verify the JWT tokens in Python ... case) into a sequence of bytes (just a...
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
Thanks @brandonmbanks
.decode('utf-8')
is working!I have the same problem -,-
I solved it with:
This is the correct way for pyjwt?