JWT: 'module' object has no attribute 'encode'
The problem arises if you have both JWT and PyJWT installed. When doing import jwt
it is importing the library JWT as opposed to PyJWT - the latter is the one you want for encoding. I did pip uninstall JWT
and pip uninstall PyJWT
then finally pip install PyJWT
. After that it imported the correct module and generated the token! :)
You can use the PyJWT package, where jwt.encode()
works fine (no need for initialization or other kinds of stuff).