I am trying to encrypt a file using pgpy. I am able to encrypt the content of files but unable to save it. I am trying to get output as .csv.pgp
Getting this error: encrypted_file.write(encrypted_f_t_e) TypeError: a bytes-like object is required, not 'PGPMessage'
import pgpy
from pgpy import PGPKey, PGPMessage
PUBLIC_KEY_FILE = 'myPublicKey.asc'
pub_key, _ = pgpy.PGPKey.from_file(str(PUBLIC_KEY_FILE))
FILE_TO_ENCRYPT = 'data.csv'
f_t_e = pgpy.PGPMessage.new(str(FILE_TO_ENCRYPT),file=True)
print(f_t_e.is_encrypted)
encrypted_f_t_e = pub_key.encrypt(f_t_e)
print(encrypted_f_t_e)
with open('data.csv.pgp', 'wb') as encrypted_file:
encrypted_file.write(encrypted_f_t_e)