xml.dom.minidom character encoding

Peter Otten __peter__ at web.de
Wed Apr 21 20:25:14 CEST 2010


C. Benson Manica wrote:

> On Apr 21, 1:58 pm, Peter Otten <__pete... at web.de> wrote:
>> C. Benson Manica wrote:
>>> (snip)
>>
>> It seems that parseString() doesn't like unicode
> 
> Yes, I noticed that, and I already tried...
> 
>> -- let's try a byte string
>> then:
>>
>> >>> doc = xml.dom.minidom.parseString(s.encode("utf-8"))
>> >>> xml = doc.toxml(encoding="utf-8")
> 
> ...except that it didn't work:
> 
>   File "./demo.py", line 8, in <module>
>     doc=xml.dom.minidom.parseString( str.encode("utf-8") )
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 62: ordinal not in range(128)

Are you sure that your script has

str = u"..."

like in your post and not just

str = "..."

?

Peter





More information about the Python-list mailing list