error when parsing xml

Fredrik Lundh fredrik at
Mon Sep 5 13:42:28 CEST 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
to open an encoded stream and print via that one instead.

more reading (google for "python unicode" if you want more):


More information about the Python-list mailing list