question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

When using a pair of RSA keys to try the example given in the docs:

encoded = jwt.encode({'some': 'payload'}, private_key, algorithm='RS256')
decoded = jwt.decode(encoded, public_key, algorithms='RS256')

Expected Result

I’m expecting to get both variables assigned without problem.

Actual Result

But what happens instead is that I’m getting:

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

Reproduction Steps

import jwt
private_key = open("private.pem").read()
public_key = open("public.pem").read()
encoded = jwt.encode({'some': 'payload'}, private_key, algorithm='RS256')
decoded = jwt.decode(encoded, public_key, algorithms='RS256')

System Information

$ python -m jwt.help
{
  "cryptography": {
    "version": "1.3.2"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.5.1"
  },
  "platform": {
    "release": "18.0.0",
    "system": "Darwin"
  },
  "pyjwt": {
    "version": "1.6.4"
  }
}

This command is only available on PyJWT v1.6.3 and greater. Otherwise, please provide some basic information about your system.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:12
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rjdkolbcommented, Jun 22, 2020

Make sure you don’t mix up your private key with your public. Always verify with your public key. I was using my private key to verify and got this message. Struggled with this for about 2 hours…

0reactions
github-actions[bot]commented, Jun 17, 2022

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in python cryptography module: _RSAPrivateKey' object ...
Then use that key to sign a message. But running the program throws AttributeError: '_RSAPrivateKey' object has no attribute 'sign'.
Read more >
'_RSAPrivateKey' object has no attribute 'sign' - Deployment
... my django application with travis I got the following error when I ... (AttributeError): '_RSAPrivateKey' object has no attribute 'sign'.
Read more >
AttributeError: '_RSAPrivateKey' object has no attribute 'sign'
I am trying to create JWT token using python 2.7 and receive following error. AttributeError: '_RSAPrivateKey' object has no attribute 'sign' < ...
Read more >
'_RSAPrivateKey' object has no attribute 'encode'
What can cause this error while running the "Sample Program for the Python SDK" for the Snowpipe REST API : '_RSAPrivateKey' object has...
Read more >
Usage Examples — PyJWT 2.6.0 documentation
RSA encoding and decoding require the cryptography module. ... For example, in situations where the token issuer uses multiple keys and you have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found