En Mon, 09 Jul 2007 20:11:24 -0300, Martin <[EMAIL PROTECTED]>  
escribió:

> I get below error when trying to write unicode xml to a zipfile.
>
>     zip.writestr('content.xml', content.toxml())
>   File "/usr/lib/python2.4/zipfile.py", line 460, in writestr
>     zinfo.CRC = binascii.crc32(bytes)       # CRC-32 checksum
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u25cf' in
> position 2848: ordinal not in range(128)
>
> Any ideas?

Encode before writing. Assuming you want to use utf-8:
zip.writestr('content.xml', content.toxml().encode('utf-8'))

In general, when working with unicode, it's best to decode bytes into  
unicode as early as possible (when reading input), process only unicode  
inside the program, and encode into bytes at the last step (when writing  
output).
Some non-unicode-aware libraries may interfere with this flow,  
unfortunately.

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to