I generated a private and a public key using OpenSSL with the following commands:
openssl genrsa -out private_key.pem 512 openssl rsa -in private_key.pem -pu
To load an OpenSSL generated public key file with python-rsa library, try
with open('public_key.pub', mode='rb') as public_file: key_data = public_file.read() public_key = rsa.PublicKey.load_pkcs1_openssl_pem(key_data)