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

module 'jwt' has no attribute 'encode' #11

Closed
Allan-Nava opened this issue Apr 20, 2018 · 10 comments
Closed

module 'jwt' has no attribute 'encode' #11

Allan-Nava opened this issue Apr 20, 2018 · 10 comments

Comments

@Allan-Nava
Copy link

I want to encode with jwt.encode but I got this error.

@yosida95
Copy link
Member

Yes. The module doesn't export encode function, so an error you reported should occur.

@yosida95
Copy link
Member

As README, you must instantiate jwt.JWT class first, then use encode method of the instance.

@furqan-asghar
Copy link

AttributeError: 'dict' object has no attribute '_jws'

got this error :

File "E:\github\MyGits\TDA\rest_server_sql.py", line 113, in login
token = jwt.JWT.encode({'public_id' : user.public_id, 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=30)}, app.config['SECRET_KEY'])
File "E:\github\MyGits\TDA\venv_tda\lib\site-packages\jwt\jwt.py", line 44, in encode
return self._jws.encode(message, key, alg, optional_headers)
AttributeError: 'dict' object has no attribute '_jws'

while generating token:
token = jwt.JWT.encode({'public_id' : user.public_id, 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=30)}, app.config['SECRET_KEY'])

@yosida95
Copy link
Member

yosida95 commented Aug 20, 2018

@furqan-asghar Your problem is not relative to this one, and as you're already doing, your problem will be discussed on #15.

@ranjannandi
Copy link

After putting JWT before encode this is happening

AttributeError: module 'jwt' has no attribute 'JWT'

@yosida95
Copy link
Member

yosida95 commented Oct 4, 2018

@ranjannandi Please provide minimum reproducible code, and also jwt version you're using.

@richmidwinter
Copy link

I hit a similar issue with a test script in a filename of jwt.py - renamed it and it worked.

@antarts
Copy link

antarts commented Dec 13, 2019

use "pip install pyjwt"

@ManuZhu
Copy link

ManuZhu commented May 6, 2020

you can check whether your code is name "jwt.py",if so,change it

@yosida95
Copy link
Member

yosida95 commented Jul 15, 2020

Your script is named jwt.py, or jwt.py exists in the same directory as the script

Rename jwt.py, or import jwt imports your script instead of the jwt library.

Both the jwt library and PyJWT are installed

There is a known name crash #9. Use either the jwt or PyJWT exclusively.

Despite the above, the problem still exists

Make sure you are calling the encode method of a jwt.JWT() instance. See #15 and the README example.

If this is not the case, please file an issues.

@GehirnInc GehirnInc locked as resolved and limited conversation to collaborators Jul 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants