Help needed with python unicode cgi-bin script

"Martin v. Löwis" martin at v.loewis.de
Tue Dec 11 18:31:16 EST 2007


> Thanks for your help and kind words of encouragement. Still, what you have 
> suggested doesn't seem to work, unless I'm not understanding your directive 
> to encode as 'windows-1252'.

Please read John's message again. Nowhere he said you should "encode as
'windows-1252'". Instead, he said 'use charset="windows-1252"'.

> print u"""Content-Type: text/html

In one message, you said "somehow my cut and paste job into outlook
missed the exact line you had above that specifies encoding tp be set as
"utf8", but it's there in my program"

What EXACTLY do you mean by that? Where PRECISELY did you set
"encoding tp" (what is tp?) to "utf8"?

I suggested doing that in the Content-type CGI/HTTP header, but
perhaps you do it in the http-equiv HTML element instead:

> <meta http-equiv="content-type" content="text/html; charset=windows-1252" />

So this should work fine.

> x = repr(open('c:/test/spanish.txt','rb').read())
> print '<p>',x,'# first print</p>'

It's no suprise that this prints an escaped text, because that's
what repr() does.

> x = open('c:/test/spanish.txt','rb').read()
> print '<p>',x,'# second print</p>'

This should work fine.

> a?o # second print  #### Note that there is no ñ between the a and the o, 
> only a box

What does the browser say what the encoding of the page is?

What browser are you using, and did you configure it to default to
UTF-8 for all pages? (which you should not have done)

Try "telnet server 80", then type

GET /path HTTP/1.1<enter>
Host: server<enter>
<enter>

and report what response from the server is (the complete one,
not just the character in question)

Regards,
Martin



More information about the Python-list mailing list