'Error while trying to decrypt a RSA encrypted text

I am a newbie when it comes to Python, and I have only recently begun to learn the language. I was intrigued by the idea of encryption, so I began to experiment with RSA.

I use the version 4.8 of RSA.

However, I am unable to decrypt the encrypted message using the private key since I get an error:

    Traceback (most recent call last):
  File "C:\Users\darko\PycharmProjects\TestingPY\decryption test.py", line 6, in <module>
    decrypted = rsa.decrypt(encrypted, privatekey).decode()
  File "C:\Users\darko\PycharmProjects\TestingPY\venv\lib\site-packages\rsa\pkcs1.py", line 254, in decrypt
    blocksize = common.byte_size(priv_key.n)
AttributeError: 'str' object has no attribute 'n'

Can someone help me?

The Python script is this:

import rsa

encrypted = input("Input encrypted text to decrypt: ")
privatekey = input("Input PrivateKey to decrypt: ")

decrypted = rsa.decrypt(encrypted, privatekey).decode()
print("Decrypted: " + str(decrypted))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source