4

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'
7
  • Does this answer your question? JWT: 'module' object has no attribute 'encode' Commented Jul 20, 2020 at 14:27
  • 2
    Tried uninstalling pyjwt, still it is giving the same error. Commented Jul 20, 2020 at 15:03
  • Try changing the folder name 'jwt Commented Jul 20, 2020 at 15:10
  • 1
    And also try jwt.JWT().encode(...) Commented Jul 20, 2020 at 15:14
  • 1
    @RoshinRaphel, changed the folder name, it is still the same. Commented Jul 20, 2020 at 15:51

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.