jwt.encode returns str instead of bytes in 2.0.0a1
See original GitHub issueLatest pre-release 2.0.0a1 brings change of function jwt.encode, that doesn’t return bytes as in release 1.7.1, but str. Is it a bug or will it stay that way?
I am asking, because it breaks https://github.com/SimpleJWT/django-rest-framework-simplejwt and I need to know where the fix should be done.
Expected Result
jwt.encode
to return bytes
Actual Result
jwt.encode
returns str
Reproduction Steps
import jwt
encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
print(encoded)
System Information
$ python -m jwt.help
{
"cryptography": {
"version": "3.1"
},
"implementation": {
"name": "CPython",
"version": "3.7.3"
},
"platform": {
"release": "5.9.1-arch1-1",
"system": "Linux"
},
"pyjwt": {
"version": "2.0.0a1"
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
API Reference — PyJWT 2.0.0a1 documentation
Verify the jwt token signature and return the token claims. Parameters: jwt (str|bytes) – the token to be decoded; key (str) – ...
Read more >JWT is being converted from str to bytes on requests.post()
Why do I get this error even though the type was converted to string ? EDIT: I was able to successfully retrieve the...
Read more >PyJWT - Release 2.6.0 - Read the Docs
decoded = jwt.decode(encoded, public_key, algorithms=["RS256"]) ... return type. Tokens are returned as string instead of a byte string.
Read more >python-jwt Changelog - pyup.io
2.0.1. Not secure ... Tokens are returned as string instead of a byte string ... Update return type for jwt.encode (521) by moomoolive...
Read more >sql-api-generate-jwt.py
ALGORITHM) # If you are using a version of PyJWT prior to 2.0, jwt.encode returns a byte string, rather than a string. #...
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
It is in fact an expected change.
I appreciate the feedback, thanks.
While I do agree that I could’ve planned out a whole series of releases with deprecation warnings, compatibility layers, and the whole lot, I ultimately decided against that because that does take time and energy to execute. I knew I wanted to make breaking changes, I knew I wanted to add new features, address bugs, etc so I decided to just release new major version.
I’d say this is part of the problem, one I shouldn’t have to be necessarily constrained by. I’d argue that everyone should just be pinning the versions of their dependencies down to specifics, going from one version to another(specially major versions) isn’t a thing to be taken lightly, it needs some level of due diligence either by computers(CI, tests, automation, etc) or humans(docs, release notes, etc).
Anyways, something I’ll continue keeping in mind for future releases. ✌️