Help needed python unicode cgi-bin

Reply

Join Date: Dec 2007
Posts: 3
Reputation: skibum_not is an unknown quantity at this point 
Solved Threads: 0
skibum_not skibum_not is offline Offline
Newbie Poster

Help needed python unicode cgi-bin

 
0
  #1
Dec 8th, 2007
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:

  1. #!C:/Program Files/Python23/python.exe
  2.  
  3. STARTHTML= u'''Content-Type: text/html
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  7. <head>
  8. </head>
  9. <body>
  10. '''
  11. ENDHTML = u'''
  12. </body>
  13. </html>
  14. '''
  15. print STARTHTML
  16. print open('c:/test/spanish.txt','r').read()
  17. 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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: Help needed python unicode cgi-bin

 
0
  #2
Dec 21st, 2007
hi,

read this. This might help you.

kath.
Last edited by katharnakh; Dec 21st, 2007 at 6:26 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 3
Reputation: skibum_not is an unknown quantity at this point 
Solved Threads: 0
skibum_not skibum_not is offline Offline
Newbie Poster

Re: Help needed python unicode cgi-bin

 
0
  #3
Dec 22nd, 2007
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.

Originally Posted by katharnakh View Post
hi,

read this. This might help you.

kath.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC