In python writing from XML to CSV, encoding error

Posted by user574435 on Stack Overflow See other posts from Stack Overflow or by user574435
Published on 2011-01-17T21:35:23Z Indexed on 2011/01/17 21:53 UTC
Read the original article Hit count: 225

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about Xml