Charset HTTP header switched to UTF-8. Bug or feature ?
Hi, There's a strange thing in a iso-8859-1 (natural) charset site Zope 2.6.1 powered... A form is summitted (POST) to a TTW python script. At the end of the script, after form validation ... <sample> return context.sometemplate(param1=value1, ...) </sample> The "sometemplate" is published with this HTTP header : Content-Type: text/html;charset=UTF-8 When nowhere in my scripts/templates, I stated to use that charset. You can imagine the ugly things that are displayed :-/ I found a workaround: forcing the HTTP header of the response... <sample> REQUEST.RESPONSE.setHeader('Content-Type', 'text/html; charset=iso-8859-1') return context.sometemplate(param1=value1, ...) </sample> Is this behavior a bug or a feature ? Note that with older versions of Zope (2.3.3) I didn't need to force the charset header like this. Thanks in advance --Gilles
Gilles Lenfant wrote:
The "sometemplate" is published with this HTTP header :
Content-Type: text/html;charset=UTF-8
When nowhere in my scripts/templates, I stated to use that charset. You can imagine the ugly things that are displayed :-/
Toby Dickenson would be the man to ask, IIRC. Have you set UTF-8 as a default anywhere on your system?
I found a workaround: forcing the HTTP header of the response...
<sample> REQUEST.RESPONSE.setHeader('Content-Type', 'text/html; charset=iso-8859-1')
return context.sometemplate(param1=value1, ...) </sample>
What about putting a meta declaration in the <head>? At least you don't have the clunky python code then... cheers, Chris
----- Original Message ----- From: "Chris Withers" <chrisw@nipltd.com> To: "Gilles Lenfant" <gilles@pilotsystems.net> Cc: <zope@zope.org> Sent: Thursday, August 28, 2003 12:08 PM Subject: Re: [Zope] Charset HTTP header switched to UTF-8. Bug or feature ?
Gilles Lenfant wrote:
The "sometemplate" is published with this HTTP header :
Content-Type: text/html;charset=UTF-8
When nowhere in my scripts/templates, I stated to use that charset. You can imagine the ugly things that are displayed :-/
Toby Dickenson would be the man to ask, IIRC. Have you set UTF-8 as a default anywhere on your system?
I found a workaround: forcing the HTTP header of the response...
<sample> REQUEST.RESPONSE.setHeader('Content-Type', 'text/html; charset=iso-8859-1')
return context.sometemplate(param1=value1, ...) </sample>
What about putting a meta declaration in the <head>? At least you don't have the clunky python code then...
cheers,
Chris
Thanks Chris, I tried this before patching the Python script that handles the form. Putting the charset=iso-8859-1 declaration in the <head> didn't help. The charset declaration of the HTTP header (Content-Type) has priority over the HTML charset declaration (as observed with IE and Mozilla = 99% of users). That's the reason why I ask if this is a bug or a feature. I can't understand this because with the python engine that runs Zope...
import sys sys.getdefaultencoding() iso-8859-1
And my system locales are set to that charset too. If it's a feature, is there some place where we can stand what charset should be used for publishing objects behind such or such folder. After further tests, I noticed this on DTML as well as ZPT templates. Cheers --Gilles
Gilles Lenfant wrote:
import sys sys.getdefaultencoding()
iso-8859-1
Shouldn't that be ASCII?
And my system locales are set to that charset too. If it's a feature, is there some place where we can stand what charset should be used for publishing objects behind such or such folder. After further tests, I noticed this on DTML as well as ZPT templates.
Like i said, you'd have to ask someone who knows. Submitting a collector issue is about the best I can offer, sorry :-S Chris
----- Original Message ----- From: "Chris Withers" <chrisw@nipltd.com> To: "Gilles Lenfant" <gilles@pilotsystems.net> Cc: <zope@zope.org> Sent: Friday, August 29, 2003 3:59 PM Subject: Re: [Zope] Charset HTTP header switched to UTF-8. Bug or feature ?
Gilles Lenfant wrote:
import sys sys.getdefaultencoding()
iso-8859-1
Shouldn't that be ASCII?
No, I changed it cause there are lots of "UnicodeError: char not in range(128)" if I stay ASCII with some products. That's OK now. But this has - apparently - no connection with the problem I stated.
And my system locales are set to that charset too. If it's a feature, is there some place where we can stand what charset should be used for publishing objects behind such or such folder. After further tests, I noticed this on DTML as well as ZPT templates.
Like i said, you'd have to ask someone who knows. Submitting a collector
issue
is about the best I can offer, sorry :-S
You're right, gonna do this. Cheers --Gilles
Gilles Lenfant wrote:
import sys sys.getdefaultencoding()
iso-8859-1
Shouldn't that be ASCII?
No, I changed it cause there are lots of "UnicodeError: char not in range(128)" if I stay ASCII with some products. That's OK now. But this has - apparently - no connection with the problem I stated.
Hmmm, I have a gut feeling that this isn't the corerct solution to the problem you're experiencing. See if you can consult some python unicode gurus on #python or comp.lang.python... cheers, Chris
Gilles Lenfant wrote:
There's a strange thing in a iso-8859-1 (natural) charset site Zope 2.6.1 powered...
A form is summitted (POST) to a TTW python script. At the end of the script, after form validation ...
<sample> return context.sometemplate(param1=value1, ...) </sample>
The "sometemplate" is published with this HTTP header :
Content-Type: text/html;charset=UTF-8
When nowhere in my scripts/templates, I stated to use that charset. You can imagine the ugly things that are displayed :-/
Does your script call a manage_*-method (manage_changePropeties for example, which alway sets the management-charset to UTF-8 since Zope 2.6.1) or does it catalog an item? Cheers, Maik
----- Original Message ----- From: "Maik Jablonski" <maik.jablonski@uni-bielefeld.de> To: <zope@zope.org> Sent: Friday, August 29, 2003 4:41 PM Subject: [Zope] Re: Charset HTTP header switched to UTF-8. Bug or feature ?
Gilles Lenfant wrote:
There's a strange thing in a iso-8859-1 (natural) charset site Zope 2.6.1 powered...
A form is summitted (POST) to a TTW python script. At the end of the script, after form validation ...
<sample> return context.sometemplate(param1=value1, ...) </sample>
The "sometemplate" is published with this HTTP header :
Content-Type: text/html;charset=UTF-8
When nowhere in my scripts/templates, I stated to use that charset. You can imagine the ugly things that are displayed :-/
Does your script call a manage_*-method (manage_changePropeties for example, which alway sets the management-charset to UTF-8 since Zope 2.6.1) or does it catalog an item?
Hi Maik, You're right... When the page is POSTed from a form, the script makes some manage_changeProperties(...). I got to explicitely reset that charset to iso-8859-1 in the RESPONSE to get rid of this ugly display on non ASCII characters like é, ç, à (...). This is a strange choice. Zope "natural" charset is supposed to be iso-8859-1 and should always use that charset without further programmer notice. Cheers --Gilles
participants (3)
-
Chris Withers -
Gilles Lenfant -
Maik Jablonski