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

Yuri yurj at alfa.it
Tue Nov 15 06:57:44 UTC 2011


Il 11/11/2011 13:40, morten at nidelven-it.no ha scritto:
> 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.  :)
>
> -Morten

Even forcing utf-8 in the content-type header, I still have this error 
on some web browser. For example, mozilla firefox 3.6.18 on windows 
gives this error:

Error Type: DataError
Error Value: invalid byte sequence for encoding "UTF8": 0xe82075 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".

It's sad there's no standard or no way to be compliant.


More information about the Zope mailing list