I'm using the python rsa module to generate a public/private key pair. I want to send the public key to the other computer through a socket connection.
When I try to encode the public key to send it, I get this error:
File "chatclient.py", line 128, in <module>
s.sendall(pubkey.encode('utf-8'))
AttributeError: 'PublicKey' object has no attribute 'encode'
I cannot figure out a way to encode the key other than the method that causes the error. If I try to convert it to a string, encode it and send it through, I cannot use the key to encrypt any messages, nor are there any documented ways to turn it back into a PublicKey object.
This is what causes the error:
s.sendall(pubkey.encode('utf-8'))
Here's the package on pypi and the documentation:
PublicKeyclass defined?.encodeis usually a string thing what type of object ispubkey? check to see if it already haves abytesorto_bytesmethodsave_pkcs1and load it from said string withload_pkcs1.