xml.dom.minidom.parse(fname).save() still complains about UnicodeError...

juha.o.ylitalo at kolumbus.fi juha.o.ylitalo at kolumbus.fi
Thu Nov 14 01:09:22 EST 2002


Platform: RedHat Linux 8.0
Python: python 2.2.1 from RedHat as well as 
        python 2.2.2, which I compiled from source.

I am trying to create small script, which would simply parse existing
XML file, add some new information in and write back to file. When I
started to troubleshoot my problem, I ended up with following problem:

[jylitalo at shoes jylitalo]$ /usr/local/bin/python
Python 2.2.2 (#1, Nov 13 2002, 23:25:41)
[GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.dom.minidom
>>> d = xml.dom.minidom.parse("catalog.phojo")
>>> print d.toxml()

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>>

File itself has non-english letters in it and it is supposed to be
UTF-8 encoded. What makes this problem very weird is that I have
separate script, which has graphical userinterface, etc. I am able to
do all kind of parse that same DOM tree, rebuild it and successfully
write it down to same file without any UTF-8 complains (I use
prettyxml when I save new DOM tree).
When I searched around with google, I came up with similar kind of
problems, but only ones that really matched my case required some
patching to StringIO module to work. Is this still the case or have I
simply missed something....

--
juha.o.ylitalo at kolumbus.fi



More information about the Python-list mailing list