djangorestframework-simplejwt: Possible bug: 'str' object has no attribute 'decode' after PyJWT upgrade from 2.0.0a1 to 2.0.0

Recently the PyJWT package has been updated and is throwing this error when generating a token.

PyJWT latest version: https://github.com/jpadilla/pyjwt/releases/tag/2.0.0

The exception is raised in: rest_framework_simplejwt/backends.py in encode at line 43

just in return token.decode('utf-8') line

I have solved it by explicitly putting the PyJWT package in my requirements.txt file, just below djangorestframework-simplejwt

version that introduces the error: PyJWT==2.0.0

downgraded version to make it work: PyJWT==v1.7.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 17 (11 by maintainers)

Most upvoted comments

I am using djanago 2.2.16 with python 3.6.12 I faced same issue. By using djangorestframework-simplejwt==4.4.0 and PyJWT==1.7.1 it works.

djangorestframework-simplejwt==4.4.0 PyJWT==1.7.1

There is and a PR was made for it at #348, but David’s not really active when it comes to maintenance here, so I’m working out a plan to get a patch version out to merge #348 if need be or just increase the minor version when I get the time to upgrade everything to be compatible with PyJWT 2.0.0.

For now, I think my game plan is to get a minor version by 26 December.

@Andrew-Chen-Wang That is exactly what it is, I should have noticed, and thats the main difference between my local and heroku. My local is on python 3.8.3, while my heroku is on 3.6.

Thanks!

@NicholasWSmith I wonder if you’re on Python 3.6…? David mandated that your Python version be 3.7 and above for this to work (kinda sucks, but it’s to force people to upgrade).

If you’re on 3.7 and above, you should probably update a requirements.txt file to reflect the 4.6.0 if you’re doing recursive installation from a file. I find it kinda strange that it can’t find 4.6.0.