reload(sys)

Steven Bethard steven.bethard at gmail.com
Sun Sep 2 22:40:35 EDT 2007


Sönmez Kartal wrote:
> I was using the XMLBuilder(xmlbuilder.py). I'm writing XML files as
> "f.write(str(xml))". At execution of that line, it gives error with
> description, configure your default encoding...
>
[and later]
>
> I get this when it happens: "Decoding Error: You must configure
> default encoding" which comes from in the code excerpt in
> xmlbuilder.py (http://rafb.net/p/9rURi822.html)

Can you show the code where you populate the XMLBuilder? I'm guessing 
you're doing something like::

     import xmlbuilder
     builder = xmlbuilder.XMLBuilder()
     builder.foo = dict(bar='® and ™')
     str(builder)

That breaks because the string '® and ™' is not properly encoded. Have 
you declared an encoding in your source file? PEP 263 shows you how:

     http://www.python.org/dev/peps/pep-0263/

Note that with Python 2.5 the code above gives a SyntaxError without a 
proper encoding. You should also probably be prefixing your string 
literals containing weird characters with "u" to make them unicode. 
Doing both of these in the code above made it work for me.

STeVe



More information about the Python-list mailing list