[Zope-dev] Localizer and UnicodeError
Dieter Maurer
dieter at handshake.de
Sat Dec 20 05:57:27 EST 2003
Milos Prudek wrote at 2003-12-16 17:38 +0100:
> ...
>Error Type: UnicodeError
>Error Value: ASCII encoding error: ordinal not in range(128)
>
>The same error is triggered when displaying the titles in that folder:
>
>script_1:
>
>for x in context.objectValues('LocalContent'):
> print x.id, ":" x.title
>return printed
>
>... and is not trigered if I only list the ids.
>
>I believe that this kind of error appears when Zope is trying to display
>Unicode characters and legacy-encoded characters (such as ISO-8859-2 or
>Win1250) at the same time.
You are almost right:
Whenever Python (thus, this is not restricted to Zope) combines
a normal string and a unicode string, it tries to convert
the normal string into unicode. In this conversion,
it uses Python's "defaultencoding" (defaults to ASCII).
When the normal string contains characters not supported
by this encoding, you get error like the above.
The general advice is: "Unicode everywhere or nowhere".
Because I live in a "Latin-1" environment (with no other encodings
around), I can live with a hack (frowned upon by many Python gods):
I set Python's default encoding to "iso-8859-15". This
can only be done in Python's initialization because later
"sys.setdefaultencoding" is no longer available.
As you want to specifically support many languages, this is
probably no option for you. Therefore: go for the "Unicode everywhere"
option...
--
Dieter
More information about the Zope-Dev
mailing list