minidom's setAttribute + UnicodeDecodeError

Ruslan alienoid at
Tue Sep 7 16:41:20 CEST 2004

Hi, everybody.
In this excerpt of code

enc = 'some_type_of_encoding'

def _encode(v):
    if isinstance(v, UnicodeType):
        v = v.encode(v)
    return v

node.setAttribute('style:name', _encode(value))

i get UnicodeDecodeError:
Traceback (most recent call last):
  File "", line 107, in ?
  File "", line 63, in replace
    node.setAttribute('style:name', _encode(uval))
  File "/usr/local/lib/python2.3/site-packages/_xmlplus/dom/",
line 704, in setAttribute
    elif value != attr.value:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 14:
ordinal not in range(128)

The value passed to setAttribute is utf8 string, i tried with different
encodings, but no luck.
Could somebody give any suggestion how to solve that? Seems problem is
in 'ascii' codec in minidom, but how to make it handle not just ascii?

P.S. Tested with python2.3.3 & python2.3.4

Best regards,

More information about the Python-list mailing list