question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jwt.encode returns str instead of bytes in 2.0.0a1

See original GitHub issue

Latest 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:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
jpadillacommented, Nov 4, 2020

It is in fact an expected change.

3reactions
jpadillacommented, Jan 17, 2021

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.

It’s often specified simply pyjwt in dependencies without version restrictions.

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. ✌️

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found