jpadilla / pyjwt

JSON Web Token implementation in Python
https://pyjwt.readthedocs.io
MIT License
5.11k stars 684 forks source link

jwt.decode returns Attribute error ('str' object has no attribute 'decode') for version 2.6.0 #877

Closed Diwura closed 1 year ago

Diwura commented 1 year ago

Summary.

Expected Result

the .decode method should return a value after using jwt.encode to encode the payload. What you expected.

Actual Result

Attribute error: 'str' object has no attribute 'decode' What happened instead. Attribute error: 'str' object has no attribute 'decode'

Reproduction Steps

work around involved using a lower version specifically 1.7.1

import jwt

System Information

$ python -m jwt.help
<paste here>

This command is only available on PyJWT v1.6.3 and greater. Otherwise, please provide some basic information about your system.

Viicos commented 1 year ago

You are probably not doing things the intended way. Please provide at least a MRE

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

mSharifHub commented 3 months ago

If you using a django app with a newer version of pyJWT it does not need the utf-8 to decode in newer version.

from:

def jwt_encode(payload, context=None): return jwt.encode( payload, jwt_settings.JWT_SECRET_KEY, jwt_settings.JWT_ALGORITHM, ).decode('utf-8')

to

def jwt_encode(payload, context=None): return jwt.encode( payload, jwt_settings.JWT_SECRET_KEY, jwt_settings.JWT_ALGORITHM, )

file should be in .venv you create for project. example

cd /path/to/your/project/venv/lib/python3.12/site-packages/graphql_jwt