Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aaronn opened this issue Nov 3, 2020 · 20 comments
Closed

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

aaronn opened this issue Nov 3, 2020 · 20 comments
Labels

Comments

@aaronn
Copy link

aaronn commented Nov 3, 2020

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'
@Andrew-Chen-Wang
Copy link
Member

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

@the-papi
Copy link
Contributor

the-papi commented Nov 3, 2020

jpadilla/pyjwt#529

@aaronn
Copy link
Author

aaronn commented Nov 3, 2020

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

@Andrew-Chen-Wang
Copy link
Member

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!

@Andrew-Chen-Wang
Copy link
Member

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

@the-papi
Copy link
Contributor

the-papi commented Nov 4, 2020

Fixed by #329

@Andrew-Chen-Wang
Copy link
Member

Closed in release 4.6.0

@shredding
Copy link

shredding commented Dec 22, 2020

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

@DannyLee12
Copy link

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

@shredding
Copy link

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.

@Andrew-Chen-Wang
Copy link
Member

Andrew-Chen-Wang commented Dec 22, 2020

@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)...

@eviey
Copy link

eviey commented Dec 22, 2020

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.

@Andrew-Chen-Wang
Copy link
Member

Andrew-Chen-Wang commented Dec 22, 2020

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

@Andrew-Chen-Wang
Copy link
Member

Andrew-Chen-Wang commented Dec 22, 2020

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

@manickbhan
Copy link

manickbhan commented Dec 23, 2020

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

@manickbhan
Copy link

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

@shredding
Copy link

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.

@manickbhan
Copy link

manickbhan commented Dec 23, 2020 via email

@Andrew-Chen-Wang
Copy link
Member

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!

@jazzband jazzband locked as resolved and limited conversation to collaborators Dec 24, 2020
@Andrew-Chen-Wang
Copy link
Member

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.

10cheon00 referenced this issue in 10cheon00/drf-practice Jun 21, 2021
ridvanaltun added a commit to ridvanaltun/notebin that referenced this issue Jul 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants