Help needed with python unicode cgi-bin script

weheh weheh at verizon.net
Mon Dec 10 17:55:00 EST 2007


Hi Martin, thanks for your response. My updates are interleaved with your
response below:


> What is the encoding of that file? Without a correct answer to that
> question, you will not be able to achieve what you want.

I don't know for sure the encoding of the file. I'm assuming it has no
intrinsic encoding since I copied the word "año" into vim and then saved it
as the example text file called, "spanish.txt".

> Possible answers are "iso-8859-1", "utf-8", "windows-1252", and "cp850"
> (these all support the word "año")
>
>> Instead of seeing "año" I see "a?o".
>
> I don't see anything here. Where do you see the question mark? Did you
> perhaps run the CGI script in a web server, and pointed your web browser
> to the web page, and saw the question mark in the web browser?

The cgi-bin scripts prints to stdout, i.e. to my browser, and when I use
print I see a square box where the ñ should be. When I use print repr(...) I
see 'a\xf1o'. I never see the desired 'ñ' character.


Sending "Content-type: text/html" is not enough. The web browser needs
> to know what the encoding is. So you should send
>
> Content-type: text/html; charset="your-encoding-here"

Sorry, 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. Not to worry.

> Use "extras/page information" in Firefox to find out what the web
> browser thinks the encoding of the page is.

Firefox says the page is UTF8.

> P.S. Please, stop shouting.

OK, it's just that it hurts when I've been pulling my hair out for days on
end over a single line of code. I don't want to go bald just yet.





More information about the Python-list mailing list