Djangorestframework-simplejwt: AttributeError: 'str' object has no attribute 'decode'.

Created on 3 Nov 2020  ·  20Comments  ·  Source: jazzband/djangorestframework-simplejwt

Hey– I'm trying to get this package integrated and I'm getting something odd here when a jwt is being created. Is anyone else running into this issue? I'm on 4.4.0

AttributeError: 'str' object has no attribute 'decode'.

  File "/.../.venv/lib/python3.7/site-packages/rest_framework_simplejwt/tokens.py", line 226, in for_user
    token=str(token),
  File "/.../.venv/lib/python3.7/site-packages/rest_framework_simplejwt/tokens.py", line 82, in __str__
    return token_backend.encode(self.payload)
  File "/.../.venv/lib/python3.7/site-packages/rest_framework_simplejwt/backends.py", line 43, in encode
    return token.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
bug

Most helpful comment

Still having it on 4.6.0. Started a few hours ago, out of the blue.

All 20 comments

What version of jwt do you have? Ref: #325

Ah yes looks like I was on 2.0.0. I have downgraded to 1.7.1 for now.

We're working on the fix @aaronn lots of breaking changes happening lately, so I'll nudge David a bit for getting it out sooner. Sorry!

327 should come out in the next release (maybe a quick patch release).

Fixed by #329

Closed in release 4.6.0

Still having it on 4.6.0. Started a few hours ago, out of the blue.

4.6.0 Didn't fix all of my issues, but pinning jwt to 1.7.1 did.

FWIW:

requirements.txt

jwt==1.7.1
djangorestframework_simplejwt==4.5.0

I had a single import of jwt in my code and it used jwt.encode, and broke since it used the one pinned to simplejwt, so i had to update that as well.

@DannyLee12 If you upgraded to 4.6.0 and used PyJWT 2.0, what was your traceback? You might want to check if the problem is the same as @shredding (assuming shredding fixed the error)...

Downgraded manually from PyJWT==2.0.0 to PyJWT==1.7.1 and solved our problem

pip install PyJWT==1.7.1

We are using djangorestframework==3.12.1 and djangorestframework-simplejwt==4.4.0 on our requirements.txt and that gave us automatically the 2.0.0 version dependency.

That's your problem. You need to upgrade to 4.6.0 for simplejwt @argerick @DannyLee12 . That way, you can use PyJWT 2.0.0. Edit (2020-12-24): SimpleJWT does NOT support PyJWT 2.0.0 but we do support PyJWT 2.0.0a1 and 2.0.0a2 as of SimpleJWT 4.6.0)


Sorry I can't merge the changelog. Need to have some someone else review my PR before merging. It should be reflected in #344

Alright apologies. I don't understand what changed in PyJWT 2.0.0a1 to 2.0.0, but apparently it broke stuff... again (as noted in master branch). So reopening a different issue (it's a duplicate) to mark for historical purposes. Find it at #346

Happening to us too. I updated our requirements.txt (see below)... I can confirm this solution worked for our project.

PyJWT==1.7.1
djangorestframework_simplejwt==4.5.0

Contributors -- thanks for working on this library! Much needed part of DjangoRestFramework + Django (greatest framework of all time).

Yeah, it fucked up a lot of things for us in a very bad timing; but that's not at all affect any of my appreciation for your work. It's a great library and I ❤️ your work.

Long live open source software.

On Dec 23, 2020, at 12:05 AM, chp notifications@github.com wrote:


Yeah, it fucked up a lot of things for us in a very bad timing; but that's not at all affect any of my appreciation for your work. It's a great library and I ❤️ your work.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

Closing in favor of #347. Locking because people are saying the exact same thing in #346 with the issue being resolved already.

Sorry about not being able to immediately upgrade to PyJWT 2.0.0 and being stuck on 2.0.0a1 and 2.0.0a2. I've got the time now that school's done, so sit tight folks!

Ref #349 Unless you wrote verify=False, you aren't effected by this change. Simply upgrade to the already existing SimpleJWT 4.6.0 is good enough.

Please note: PyJWT 2.0.0 is supported by SimpleJWT 4.6.0. The master branch tests failed because of certain changes in PyJWT.decode (they started copying the payload first then modifying the copied version), but 4.6.0 is not effected by this change. You should be able to upgrade without a problem.

Was this page helpful?
0 / 5 - 0 ratings