[Zope] Unicode ZPT and XML woes

Jim Kutter jim at ebizq.net
Thu Nov 13 17:19:26 EST 2003


Thanks, but I'm not keen on the whole site customize thing, I'd prefer
not to muck with a Python setup for such a small part of the site.

If Guido and Martin and the like frown upon it, why did they put that
facility in there ;) ?

-jim

-----Original Message-----
From: Dieter Maurer [mailto:dieter at handshake.de] 
Sent: Thursday, November 13, 2003 4:02 PM
To: Jim Kutter
Cc: zope at zope.org
Subject: Re: [Zope] Unicode ZPT and XML woes


Jim Kutter wrote at 2003-11-13 11:08 -0500:
 > So I'm trying to write an XML RSS feed using Page Templates.
 > 
 > I'm having problems where I pull metadata out of a catalog, and try
to
 > use it as the item title for the feed 
 > 
 > --
 > ...
 > <item tal:repeat="item python: here.search.news_catalog({'post_date':
 > [here.ZopeTime()-1, here.ZopeTime()], 'post_date_usage':
 > 'range:min:max', 'sort_on':'post_date', 'sort_order':'reverse'})">
 >     <title tal:content="item/head">
 >       Title Here
 >     </title>
 > ...
 >  </item>
 > --
 > 
 > I get 
 > Error Type: UnicodeError
 > Error Value: ASCII decoding error: ordinal not in range(128)
 > 
 > It seems that I'm getting trapped in unicode hell, as that item/head
is
 > in ascii, and the ZPT is in unicode?

Something in your page was Unicode (therefore, ZPT tries to convert
everything to Unicode; this is right) and something is non Unicode
but it is non-Ascii, too. This gives you the error above.

You can convert the non-Unicode non-Ascii into Unicode explicitly
with the "unicode" builtin (you have to specify the correct encoding
of your string).


I have a different solution. However, many Python Gods (e.g. Guido and
Martin)
frown on it and think about ways to remove it from Python.

  Python has a "default encoding". By default, it is "ASCII".
  However, you can change it during startup (in your "sitecustomize.py")
  with "sys.setdefaultencoding(your_prefered_encoding)" to
  "your_prefered_encoding". After startup, "setdefaultencoding" is
  removed from "sys" (which is good).

  I live in a "latin-1" part of the world and therefore chose this
  as my default encoding.


-- 
Dieter



More information about the Zope mailing list