Python Forum

Full Version: AttributeError: '_RSAPrivateKey' object has no attribute 'sign'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am trying to create JWT token using python 2.7 and receive following error.

AttributeError: '_RSAPrivateKey' object has no attribute 'sign'

<PYTHON>jwt_token = jwt.encode(payload, self.private_key, algorithm='RS256')</PYTHON>

private key is stored in PEM format file.

Here is the error log one script execution:


Traceback (most recent call last):
File "report_sharing.py", line 349, in <module>
main()
File "report_sharing.py", line 328, in main
access_token = ims.get_access_token()
File "report_sharing.py", line 82, in get_access_token
jwt_token = self.create_jwt()
File "report_sharing.py", line 136, in create_jwt
jwt_token = jwt.encode(payload, self.private_key, algorithm='RS256')
File "/usr/lib64/python2.7/site-packages/jwt/api_jwt.py", line 55, in encode
json_payload, key, algorithm, headers, json_encoder
File "/usr/lib64/python2.7/site-packages/jwt/api_jws.py", line 105, in encode
signature = alg_obj.sign(signing_input, key)
File "/usr/lib64/python2.7/site-packages/jwt/algorithms.py", line 313, in sign
return key.sign(msg, padding.PKCS1v15(), self.hash_alg())
AttributeError: '_RSAPrivateKey' object has no attribute 'sign'

Any clue on this?