Sönmez Kartal said:
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]
products in the code is a list of dictionaries which are returned by
makeProduct function.
I'm not typing or pasting those characters into my script. So,
declaring an encoding didn't make it. :-( But, your code excerpt
runned well.
Gabriel said:
You should ensure that arguments to makeProduct are either:
- unicode objects
- ASCII strings
If you got them from some other place, decode the strings as soon as
possible into unicode. Read <
http://www.amk.ca/python/howto/unicode>
to understand what's happening
To further illustrate Gabriel's point, here is some code where I read in
some UTF8 text from a file. If you properly decode that text from UTF8,
you don't get any errors. If you forget to decode that text, you'll get
exactly the "default encoding" error you were getting before:
'<?xml version="1.0" encoding="utf-8"?><foo><bar>\xc2\xae and
\xc2\x99</bar></foo>'
Note that I didn't have to do anything with the default encoding. I
simply had to decode the text file with the appropriate codec. So,
looking at your code, I'm guessing that you need to figure out where
you're reading in the "name", "url" and "image" values, and make sure
you're properly decoding that text.
STeVe
P.S. If you can find somewhere to file a bug report for XMLBuilder, you
really should. The error instructing you to configure the default
encoding is really just wrong.