encode
data = open('img.jpg', 'rb').read() b64data = data.encode('base64')
b64data = open('base64data.txt').read() imgdata = b64data.decode('base64') fw = open('img.jpg', 'wb') fw.write(imgdata) fw.close()