builtins.TypeError: must be str, not bytes builtins.TypeError: must be str, not bytes python python

builtins.TypeError: must be str, not bytes


The outfile should be in binary mode.

outFile = open('output.xml', 'wb')


Convert binary file to base64 & vice versa. Prove in python 3.5.2

import base64read_file = open('/tmp/newgalax.png', 'rb')data = read_file.read()b64 = base64.b64encode(data)print (b64)# Save filedecode_b64 = base64.b64decode(b64)out_file = open('/tmp/out_newgalax.png', 'wb')out_file.write(decode_b64)# Test in python 3.5.2


matomo