In python writing from XML to CSV, encoding error
- by user574435
Hi, I am trying to convert an XML file to CSV, but the encoding of the XML ("ISO-8859-1") apparently contains characters that are not in the ascii codec which Python uses to write rows.
I get the error:
Traceback (most recent call last):
File "convert_folder_to_csv_PLAYER.py", line 139, in <module>
xml2csv_PLAYER(filename)
File "convert_folder_to_csv_PLAYER.py", line 121, in xml2csv_PLAYER
fout.writerow(row)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 4: ordinal not in range(128)
I have tried opening the file as follows:
dom1 = parse(input_filename.encode( "utf-8" ) )
and I have tried replacing the \xe1 character in each row before it is written. Any suggestions?