[Zope] force the output encoding to utf-8 in page templates

morten at nidelven-it.no morten at nidelven-it.no
Fri Nov 11 12:40:52 UTC 2011

On Fri, 11 Nov 2011 12:56:30 +0100, Yuri <yurj at alfa.it> wrote:
> Il 11/11/2011 12:43, Yuri ha scritto:
>> Hi all!
>>  I've a Zope2 application with Postgresql. All is ok and utf-8 but
>> page templates. This means that non utf-8 data is sent to the
>> database, and the database complain with:
>> *Error Type: DataError*
>> *Error Value: invalid byte sequence for encoding "UTF8": 0xe82527
>> HINT: This error can also happen if the byte sequence does not match
>> the encoding expected by the server, which is controlled by
>> "client_encoding".
>> *This does not happen if I manually switch the browser encoding
>> (Firefox -> View -> character encoding -> Unicode (UTF-8)) and submit
>> a form.
>> So my question is: how do I tell to page templates to output utf-8
>> instead of iso8859-15? The output_encoding property does anything.
>> Obviously, changing default-zpublisher-encoding to utf-8 works, but
>> other legacy applications will have problems on characted encoding.
>> Any idea?
>> **
> I've solved in page templates code:
>              if not response.headers.has_key('content-type'):
>                  response.setHeader('content-type', self.content_type + 
> ';charset='  + self.output_encoding) <- here add the utf-8, the 
> publisher will find this filled and avoid to put the default.
> on line 315 of ZopePageTemplate.py
> Is there a better way? Thanks!

Look for setting the default publisher encoding in the zope.conf
filesystem file and restart.  :)


More information about the Zope mailing list