builtins.TypeError: must be str, not bytes October 7, 2022 by Tarik The outfile should be in binary mode. outFile = open('output.xml', 'wb')