Help needed with python unicode cgi-bin script

Duncan Booth duncan.booth at invalid.invalid
Wed Dec 12 13:04:43 EST 2007


"weheh" <weheh at verizon.net> wrote:

> Hi Duncan, thanks for the reply.
>>>
>> FWIW, the code you posted only ever attempted to set the character
>> set encoding using an html meta tag which is the wrong place to set
>> it. The encoding specified in the HTTP headers always takes
>> precedence. This is why
>> the default charset setting in Apache was the one which applied.
>>
>> What you should have been doing was setting the encoding in the
>> content- type header. i.e. in this line of your code:
>>
>>   print u"""Content-Type: text/html
>>
>> You should have changed it to read:
>>
>>   Content-Type: text/html; charset=windows-1252
>>
>> but because you didn't Apache was quietly changing it to read:
>>
>>   Content-Type: text/html; charset=utf-8
>>
> Will this work under the following situation? Let's say the user is
> filling out a text field on a form on my website. The user has their
> browser encoding set to utf8. My website has charset=windows-1252 as
> you indicate above. Will I run into a conflict somewhere? 
> 
If you are sending the user a form you should be specifying the acceptable 
character sets with the accept-charset attribute on the form tag. Basically 
the rule should be to pick an appropriate character set and stick to it. 
don't depend on defaults, be explicit.




More information about the Python-list mailing list