[Zope] *Error Type: UnicodeDecodeError*
jose
jo at sferacarta.com
Mon Mar 21 11:01:15 EST 2005
Dieter Maurer ha scritto:
>jose wrote at 2005-3-18 11:44 +0100:
>
>
>>...
>>I have a PythonScript like this, to list the village names in serbian
>>language, and it works....
>>...
>># print container.mescat('city: ') + data[0]['head'][j][5]
>>...
>>If I change the script like this one, it doesn't work anymore:
>>...
>>print container.mescat('city: ') + data[0]['head'][j][5]
>>...
>>but I have instead the following error:
>>
>>*Error Type: UnicodeDecodeError*
>>*Error Value: 'ascii' codec can't decode byte 0xc5 in position 5:
>>ordinal not in range(128)
>>
>>
>
>Apparently "mescat('city: ')" returns unicode.
>This forces all strings combined with it to be converted to unicode.
>Python uses its "defaultencoding" for this conversion (default: "ascii").
>
>Because your "data[0]..." contains serbian characters, they
>cannot be decoded using "ascii".
>
>
>Your options:
>
> * use the "unicode" function to convert "data[0]..."
> to unicode.
>
> You must provide the correct encoding as second
> argument (otherwise, you get the same error).
>
> * change Python's "defaultencoding" with
> "sys.setdefaultencoding(the_encoding)".
>
> This is only possible at startup (usually done
> in "sitecustomize.py".
>
> Unicode fanatics do not like this solution...
>
>
>
I would like to follow your tip by changing sitecustomize.py but I am
fear that a such global configuration maybe will change some unwanted
behavior in other Zope modules.
Could you ensure me there are no collateral effect with other modules?
jo
More information about the Zope
mailing list