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? I've tried every combination of encoding the head string (tuf8, utf16, ascii) with either replace or ignore, with no luck. Aside from re-implenting the stream as a DTML or Python script what can I do? I've already also tried the "LOCALIZER_USE_ZOPE_UNICODE=yes" suggestion from the list archives. -jim
Jim Kutter wrote:
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?
I've tried every combination of encoding the head string (tuf8, utf16, ascii) with either replace or ignore, with no luck.
Aside from re-implenting the stream as a DTML or Python script what can I do?
I've already also tried the "LOCALIZER_USE_ZOPE_UNICODE=yes" suggestion from the list archives.
Hey, I've got that bug on my desk right now (along with a number of other unicode problems in the Zope core.) I don't know what to do about it yet (I can't get to it until at least tomorrow), but I have a feeling that my solution is going to be a patch against the core. --jcc -- "Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design." (http://www.devx.com/java/editorial/15511)
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
participants (3)
-
Dieter Maurer -
J Cameron Cooper -
Jim Kutter