Re: Help needed with python unicode cgi-bin script

2007-12-12 Thread Martin v. Löwis
> 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. It rather looks like that you didn't follow the suggestions carefully. In my very first message, I wrote # Sending "Content-type: text/html"

Re: Help needed with python unicode cgi-bin script

2007-12-12 Thread Duncan Booth
"weheh" <[EMAIL PROTECTED]> wrote: > Hi Duncan, thanks for the reply. >>> >> 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

Re: Help needed with python unicode cgi-bin script

2007-12-12 Thread weheh
Hi Duncan, thanks for the reply. >> > 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 Ap

Re: Help needed with python unicode cgi-bin script

2007-12-12 Thread Duncan Booth
"weheh" <[EMAIL PROTECTED]> 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 incorre

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
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=utf

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread John Machin
On Dec 12, 11:06 am, "weheh" <[EMAIL PROTECTED]> wrote: > p.s. I modified the code to break things out more explicitly: > > #!C:/Program Files/Python23/python.exe > import cgi, cgitb > import sys, codecs > import os,msvcrt > > cgitb.enable() > > print u"""Content-Type: text/html > > "http://www.w3

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
p.s. I modified the code to break things out more explicitly: #!C:/Program Files/Python23/python.exe import cgi, cgitb import sys, codecs import os,msvcrt cgitb.enable() print u"""Content-Type: text/html http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; > http://www.w3.org/1999/xhtml";

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
> 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) > Browser is both IE and Firefox. IE is defaulting to UTF8. If I force it to "Encoding > Western European (Wi

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread Martin v. Löwis
> 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

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
John & Martin, 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'. Here's my program in full: #!C:/Program Files/Python23/python.exe import cgi, cgitb import sys, code

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread Martin v. Löwis
> No what? YES, the "decode error" is complaining that the data supplied > is NOT valid utf-8 data. So it's not utf-8, it's windows-1252, so stop > lying to browsers: like I said, use charset="windows-1252" I think weheh can manage to resist good advise for a long time. Regards, Martin -- http:/

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread John Machin
On Dec 12, 4:46 am, "weheh" <[EMAIL PROTECTED]> wrote: > Hi John: > Thanks for responding. > > >Look at your file using > > > print repr(open('c:/test/spanish.txt','rb').read()) > > >If you see 'a\xf1o' then use charset="windows-1252" > > I did this ... no change ... still see 'a\xf1o' So it's

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
Hi John: Thanks for responding. >Look at your file using > print repr(open('c:/test/spanish.txt','rb').read()) >If you see 'a\xf1o' then use charset="windows-1252" I did this ... no change ... still see 'a\xf1o' >else if you see 'a\xc3\xb1o' then use charset="utf-8" else >Based on your

Re: Help needed with python unicode cgi-bin script

2007-12-11 Thread weheh
import sys if sys.platform == "win32": import os, msvcrt msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) "Jack" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Just want to make sure, how exactly are you doing that? > >> Thanks for the reply, Jack. I tried setting mode to

Re: Help needed with python unicode cgi-bin script

2007-12-10 Thread Jack
Just want to make sure, how exactly are you doing that? > Thanks for the reply, Jack. I tried setting mode to binary but it had no > affect. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help needed with python unicode cgi-bin script

2007-12-10 Thread John Machin
On Dec 11, 9:55 am, "weheh" <[EMAIL PROTECTED]> wrote: > 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 kno

Re: Help needed with python unicode cgi-bin script

2007-12-10 Thread weheh
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 intrin

Re: Help needed with python unicode cgi-bin script

2007-12-10 Thread weheh
Thanks for the reply, Jack. I tried setting mode to binary but it had no affect. "Jack" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > You probably need to set stdout mode to binary. They are not by default on > Windows. > > > "weheh" <[EMAIL PROTECTED]> wrote in message > news:

Re: Help needed with python unicode cgi-bin script

2007-12-09 Thread Martin v. Löwis
> 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: What is the encoding of that file? Without a correct answer to that question, you will not be able to achieve what yo

Re: Help needed with python unicode cgi-bin script

2007-12-09 Thread Jack
You probably need to set stdout mode to binary. They are not by default on Windows. "weheh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Dear web gods: > > After much, much, much struggle with unicode, many an hour reading all the > examples online, coding them, testing them,

Help needed with python unicode cgi-bin script

2007-12-09 Thread weheh
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 script