| | |
Help needed python unicode cgi-bin
![]() |
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
Dear web gods:
After much, much, much struggle with unicode, many an hour reading all the examples online, coding them, testing them, ripping them apart and putting them back together, I am humbled. Therefore, I humble myself before you to seek guidance on a simple python unicode cgi-bin scripting problem.
My problem is more complex than this, but how about I boil down one sticking point for starters. I have a file with a Spanish word in it, "años", which I wish to read with:
Instead of seeing "año" I see "a�o". BAD BAD BAD
Yet, if I open the file with the browser (IE/Mozilla), I see "año." THIS IS WHAT I WANT
WHAT GIVES?
Next, I'll get into codecs and stuff, but how about starting with this?
The general question is, does anybody have a complete working example of a cgi-bin script that does the above properly that they'd be willing to share? I've tried various examples online but haven't been able to get any to work. I end up seeing hex code for the non-ascii characters u'a\xf1o', and later on 'a\xc3\xb1o', which are also BAD BAD BAD.
Thanks -- your humble supplicant.
After much, much, much struggle with unicode, many an hour reading all the examples online, coding them, testing them, ripping them apart and putting them back together, I am humbled. Therefore, I humble myself before you to seek guidance on a simple python unicode cgi-bin scripting problem.
My problem is more complex than this, but how about I boil down one sticking point for starters. I have a file with a Spanish word in it, "años", which I wish to read with:
Python Syntax (Toggle Plain Text)
#!C:/Program Files/Python23/python.exe STARTHTML= u'''Content-Type: text/html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> </head> <body> ''' ENDHTML = u''' </body> </html> ''' print STARTHTML print open('c:/test/spanish.txt','r').read() print ENDHTML
Instead of seeing "año" I see "a�o". BAD BAD BAD
Yet, if I open the file with the browser (IE/Mozilla), I see "año." THIS IS WHAT I WANT
WHAT GIVES?
Next, I'll get into codecs and stuff, but how about starting with this?
The general question is, does anybody have a complete working example of a cgi-bin script that does the above properly that they'd be willing to share? I've tried various examples online but haven't been able to get any to work. I end up seeing hex code for the non-ascii characters u'a\xf1o', and later on 'a\xc3\xb1o', which are also BAD BAD BAD.
Thanks -- your humble supplicant.
Last edited by skibum_not; Dec 8th, 2007 at 11:32 pm.
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
http://www.daniweb.com/forums/thread102080.html
Hi Kath, thanks for the reply. Yes, I've read that already ... and many others, besides. I may have made a little breakthrough in identifying the root of my problem. But I still need a solution. Please see the thread listed above, which details the problem as I see it now. Thx again.
Hi Kath, thanks for the reply. Yes, I've read that already ... and many others, besides. I may have made a little breakthrough in identifying the root of my problem. But I still need a solution. Please see the thread listed above, which details the problem as I see it now. Thx again.
![]() |
Other Threads in the Python Forum
- Previous Thread: %A in time.strftime(%A)
- Next Thread: Good IDE
| Thread Tools | Search this Thread |
address aliased anydbm app bash beginner bits changecolor cipher clear conversion coordinates corners cturtle curves definedlines development dictionary dynamic events examples excel feet file float format function generator getvalue gui handling homework iframe images import input ip java keycontrol line linux list lists loan loop maintain matching maze millimeter mouse number numbers output parsing path port prime programming projects py2exe pygame pymailer python queue random rational raw_input recursion recursive scrolledtext searchingfile singleton slicenotation split string strings tails terminal text threading time tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable variables vigenere web whileloop word wxpython xlwt





