0

How to fix the error "JWT method 'encode' does not exist" when trying to mount a base64 for the assertion parameter of an API?

I'm trying to create a base64 to use as an "assertion" parameter in an API call, but I'm getting an error saying that the "encode" method of the JWT does not exist.

I installed using:

pip3 install jwt

Full code

import jwt

private_key = open("C:\\file\\privateKey.pem", "r").read()

payload = {
    "iss": "iss",
    "aud": "aud",
    "scope": "*",
    "iat": 1683141898,
    "exp": 1683228298
}
signed = jwt.encode(payload, private_key, algorithm='RS256')

print(signed)

Error:

    signed = jwt.encode(payload, private_key, algorithm='RS256')
             ^^^^^^^^^^
AttributeError: module 'jwt' has no attribute 'encode'
megaultron
  • 399
  • 2
  • 15

1 Answers1

0

you need to import JWT from jwt and then use encode as

from jwt import JWT
signed = JWT.encode(payload, private_key, algorithm='RS256')
sahasrara62
  • 10,069
  • 3
  • 29
  • 44