UnicodeEncodeError when writing csv file in Python



I am opening xml file, then I process something and I write CSV. At the end when writing CSV I get:


Traceback (most recent call last):

File "/home/kyselak/xml/Adler/adlerimport_2.py", line 261, in

writer.writerows(result)

UnicodeEncodeError: 'ascii' codec can't encode character u'\u010d' in position 3: ordinal not in range(128)


I have found many questions like this but still I am not able to resolve my problem.


this is XML sample, the strange thing is, that the problem is only with and not which has also central european characters:



<product>
<id_category>129</id_category>
<category>TRIČKA</category>
<name>Tričko Basic</name>
<label>ADLER</label>
<description>
Kvalitní reklamní tričko střední gramáže. Kvalitní průkrčník s přídavkem 5% elastanu se zpevňující ramenní páskou. Vhodné pro potisk a výšivku. Balení: [[!--cbl--!]] ks v kartonu, 10 ks v PE sáčku Minimální odber:1 ks Etiketa: saténová
</description>


my code is this:



import xml.etree.cElementTree as ET
tree = ET.ElementTree(file='/home/kyselak/xml/Adl/adl.xml')
.
.
.
for elem in tree.iterfind('product/description'):
description = elem.text
descriptionlist.append(description)
.
.
.
with open('/home/kyselak/xml/Adl/adl.csv', 'wb') as fin:
writer = csv.writer(fin, delimiter = ',')
writer.writerows(result)


any help would be very appreciated. thank you.


No comments:

Post a Comment