Forums

module 'jwt' has no attribute 'encode'

Hi,

I'm trying to use the PyJWT module in python 3.7.0.

I wonder why I can import the module without errors, but the encode attribute gives an error.

This is my code:

import jwt encoded = jwt.encode({'some': 'payload'}, 'secret')

I get this error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'jwt' has no attribute 'encode'

Any help is very appreciated!

BR Kresten

Do you have a file called jwt.py somewhere in your home directory, perhaps? If you do import jwt then Python will pick the first file it comes across and import that, so if the one if finds isn't the PyJWT module but instead one of your own files, things won't work.

The fix that worked for me

pip uninstall jwt PyJWT

pip cache purge

pip install PyJWT

Glad to hear that!