Problem with UnicodeError and xml.dom.minidom

Paul Prescod paulp at
Sun Jun 10 23:16:17 EDT 2001

Gustaf Liljegren wrote:
> This is line 37 in No non-ASCII characters here, and it works
> fine in Idle. I'm paralysed. Can someone break the spell?

Something is weird with your traceback. I don't see how this line could
generate this error:

  File "E:\python\_xmlplus\dom\", line 144, in appendChild
    if node.nodeType not in self.childNodeTypes:
UnicodeError: ASCII decoding error: ordinal not in range(128)

It doesn't seem to be doing string manipulations at all. There is a
"unicode" builtin that will convert text to Unicode. Sprinkle some calls
to that around like this:

assert unicode(somestring)

Sprinkle some calls to that around your code and even around the library
code if you have to.

Also, as a strategy, consider unicode-ing all of your input data as soon
as you read it in:

somestring = unicode(somestring)

Take a recipe. Leave a recipe.  
Python Cookbook!

More information about the Python-list mailing list