error when parsing xml
Fredrik Lundh
fredrik at pythonware.com
Mon Sep 5 07:42:28 EDT 2005
Odd-R. wrote:
> I use xml.dom.minidom to parse some xml, but when input
< contains some specific caracters(æ, ø and å), I get an
> UnicodeEncodeError, like this:
>
> UnicodeEncodeError: 'ascii' codec can't encode character
> u'\xe6' in position 604: ordinal not in range(128).
>
> How can I avoid this error?
if you're getting this on the way in, something is broken (posting a short
self-contained test program will help us figure out what's wrong).
if you're getting this on the way out, the problem is that you're trying to
print Unicode strings to an ASCII device. use the "encode" method to
convert the string to the encoding you want to use, or use codecs.open
to open an encoded stream and print via that one instead.
more reading (google for "python unicode" if you want more):
http://www.jorendorff.com/articles/unicode/python.html
http://effbot.org/zone/unicode-objects.htm
http://www.amk.ca/python/howto/unicode
</F>
More information about the Python-list
mailing list