Help needed with python unicode cgi-bin script

Duncan Booth duncan.booth at invalid.invalid
Wed Dec 12 04:31:52 EST 2007


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

> John and Martin,
> 
> Thanks for your help. However, I have identified the culprit to be
> with Apache and the command:
>     AddDefaultCharset utf-8
> which forces my browser to utf-8 encoding.
> 
> It looks like your suggestions to change charset were incorrect. My
> example works equally well with charset=utf8 as it does with
> charset=windows-1252. 
> 
> Incidentally, next time, if you really want to be helpful, might I
> suggest you leave out the mocking. I could care less, myself, but
> someone else might have gotten their feelings hurt. And in the end, it
> doesn't make you look good.
> 
> Thanks again. Cheers. 
> 
> 
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





More information about the Python-list mailing list