import base64with open("test.jpg", "rb") as f: file = f.read()file_base64 = base64.b64encode(file)with open("test.txt", "w") as f_1: f_1.write(file_base64.decode())