Anurag Agrawal
Anurag Agrawal

Reputation: 91

python 'jwt' module has no attribute 'encode'

This is the basic code for jwt, but it is giving me an error.

import jwt
en  = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
print(en)

ERROR

Traceback (most recent call last):
  File "C:/Users/anurag.agrawal/Desktop/HackerRank/jwt/jjwwtt.py", line 3, in <module>
    en  = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
AttributeError: module 'jwt' has no attribute 'encode'

Upvotes: 4

Views: 10932

Answers (1)

Anurag Agrawal
Anurag Agrawal

Reputation: 91

On going through various articles over the internet, finally got the solution to this problem, the library imported is to be pyjwt, as below:


from jwt import PyJWT

en = PyJWT.encode({'some' : 'payload'}, key= 'secret' , algorithm= 'RS256') print(en)


There are a few errors I am getting post this, but for now, the problem of library is resolved.

Upvotes: 2

Related Questions