[Grok-dev] Re: Understanding unicode

Philipp von Weitershausen philipp at weitershausen.de
Fri Aug 31 17:04:23 EDT 2007

Brandon Craig Rhodes wrote:
> Jan Ulrich Hasecke <janulrich.hasecke at web.de> writes:
>> zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/Users/
>> juh/GrokZoo/parts/app/site.zcml", line 4.0-4.29
>>     ZopeXMLConfigurationError: File "/Users/juh/GrokZoo/src/grokzoo/
>> configure.zcml", line 4.2-4.27
>>     UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4'
>> in position 7: ordinal not in range(128)
> In the mailing list archives from last week, I think, is my complaint
> about getting a similar message when attempting to add Unicode
> characters to a Tutorial that I am writing.
> The only solution I have found at the moment - which, I have to warn
> you, is agreed by everyone to be a quite terrible solution that might
> break everything on your system, but which worked fine for me - is to
> edit your Python site.py file, which on my system lives at:
>    /usr/lib/python2.4/site.py
> and on your site probably lives somewhere else (judging from your
> traceback), and replace the line:
>     encoding = "ascii" # Default value set by _PyUnicode_Init()
> in the "setencoding()" function (it's the 357th line in my copy) with
> the much more ambitious line:
>     encoding = "utf8"

Nooooooooooo. This isn't a solution. Nor is using 
sys.setdefaultencoding(). Trust me, if your software depends on such 
hacks, you'll have a hard time deploying, distributing and maintaining it.

A Unicode{De|En}codeError is always a sign of a bug in the application. 
Covering it up with a dirty hack is like plastering over body damage 
before selling a car...

http://worldcookery.com -- Professional Zope documentation and training

More information about the Grok-dev mailing list