Re: Unicode in cgi-script with apache2

2014-08-17 Thread Peter Otten
Dominique Ramaekers wrote: > And if I check the encoding with the python script (uncommenting line > #1), I still get ANSI_X3.4-1968 That should not matter as long as print(os.environ.get("PYTHONIOENCODING")) prints UTF-8 If you do get the correct PYTHONIOENCODING you should be able to replac

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Peter Otten
Dominique Ramaekers wrote: > As I suspected, if I check the used encoding in wsgi I get: > ANSI_X3.4-1968 > > I found you can define the coding of the script with a special comment: > # -*- coding: utf-8 -*- > > Now I don't get an error but my special chars still doesn't display well. > The scri

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Steven D'Aprano
Dominique Ramaekers wrote: > As I suspected, if I check the used encoding in wsgi I get: > ANSI_X3.4-1968 That's another name for ASCII. > I found you can define the coding of the script with a special comment: > # -*- coding: utf-8 -*- Be careful. That just tells Python what encoding the sour

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Mark Lawrence
On 17/08/2014 13:02, Dominique Ramaekers wrote: if style == TOP_POSTING: *plonk* -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Dominique Ramaekers
As I suspected, if I check the used encoding in wsgi I get: ANSI_X3.4-1968 I found you can define the coding of the script with a special comment: # -*- coding: utf-8 -*- Now I don't get an error but my special chars still doesn't display well. The script: # -*- coding: utf-8 -*- import sys de

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Dominique Ramaekers
Yes, even a restart not just reload. I Also put it in the section as in the main apache2.conf Op 17-08-14 om 13:04 schreef Peter Otten: Dominique Ramaekers wrote: Putting the lines in my apache config: AddDefaultCharset UTF-8 SetEnv PYTHONIOENCODING utf-8 Cleared my brower-cache... No c

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Peter Otten
Dominique Ramaekers wrote: > Putting the lines in my apache config: > AddDefaultCharset UTF-8 > SetEnv PYTHONIOENCODING utf-8 > > Cleared my brower-cache... No change. Did you restart the apache? -- https://mail.python.org/mailman/listinfo/python-list

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Dominique Ramaekers
Wow, everybody keeps on chewing on this problem. As a bonus, I've reconfigured my server to do some testings. http://cloudserver.ramaekers-stassart.be/test.html => is the file I want to read. Going to this url displays the file... http://cloudserver.ramaekers-stassart.be/cgi-python/encoding1 => i

Re: Unicode in cgi-script with apache2

2014-08-17 Thread Steven D'Aprano
Denis McMahon wrote: > From your other message, the error appears to be a python error on > reading the input file. For some reason python seems to be trying to > interpret the file it is reading as ascii. Oh!!! /facepalm I think you've got it. I've been assuming the problem was on *writing* the

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Steven D'Aprano
Dominique Ramaekers wrote: [...] > 2) Your tip, to use 'encode' did not solve the problem and created a new > one. My lines were incapsulted in quotes and I got a lot of \b's and > \n's... and I still got the same error. Just throwing random encode/decode calls into the mix are unlikely to fix th

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Dominique Ramaekers
* My system is a linux-box. * I've tried using encoding="utf-8". It didn't fix things. * That print uses sys.stdout would explain, using sys.stdout isn't better. * My locale and the system-wide locale is UTF-8. Using SetEnv PYTHONIOENCODING utf-8 didn't fix things * The file is encoded UTF-8

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Denis McMahon
On Sun, 17 Aug 2014 00:36:14 +0200, Dominique Ramaekers wrote: > What seems to be the problem: > My Script was ok. I know this because in the terminal I got my expected > output. Python3 uses UTF-8 coding as a standard. The problem is, when > python 'prints' to the apache interface, it translates

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Dominique Ramaekers
Hi Denis, This error is a python error displayed in the apache error log. The complete message is: [Sat Aug 16 23:12:42.158326 2014] [cgi:error] [pid 29327] [client 119.63.193.196:0] AH01215: Traceback (most recent call last): [Sat Aug 16 23:12:42.158451 2014] [cgi:error] [pid 29327] [clien

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Dominique Ramaekers
Hi Peter, Your code seems interesting. I've tried using sys.stdout (in a slightly different form) but it gave the same error. I also read about people who fixed the error by changing the servers locale to en_US.UTF-8. The people who posted these fixes also said that you can only use en_US.U

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Dominique Ramaekers
Hi John, The error is in the line "print(line,end='')"... and it only happens when the script is started from a webbrowser. In the terminal, the script works fine. See my previous mail for my findings after a lot of reading and trying... grz Op 15-08-14 om 21:32 schreef John Gordon: In D

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Dominique Ramaekers
I fond my problem, I will describe it more at the bottom of this message... But first... Thanks Alister for the tips: 1) This evening, I've researched WSGI. I found that WSGI is more advanced than CGI and I also think WSGI is more the Python way. I'm an amateur playing around with my imaginati

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Denis McMahon
On Fri, 15 Aug 2014 20:10:25 +0200, Dominique Ramaekers wrote: > #!/usr/bin/env python3 > print("Content-Type: text/html") > print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 > print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past > print("") > f = open("/var/www/cgi-dat

Re: Unicode in cgi-script with apache2

2014-08-16 Thread Peter Otten
Dominique Ramaekers wrote: > I've got a little script: > > #!/usr/bin/env python3 > print("Content-Type: text/html") > print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 > print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past > print("") > f = open("/var/www/cgi-data/ind

Re: Unicode in cgi-script with apache2

2014-08-15 Thread John Gordon
In Dominique Ramaekers writes: > #!/usr/bin/env python3 > print("Content-Type: text/html") > print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 > print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past > print("") > f = open("/var/www/cgi-data/index.html", "r") > for lin

Re: Unicode in cgi-script with apache2

2014-08-15 Thread alister
On Fri, 15 Aug 2014 20:10:25 +0200, Dominique Ramaekers wrote: > Hi, > > I've got a little script: > > #!/usr/bin/env python3 print("Content-Type: text/html") > print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 > print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past >

Unicode in cgi-script with apache2

2014-08-15 Thread Dominique Ramaekers
Hi, I've got a little script: #!/usr/bin/env python3 print("Content-Type: text/html") print("Cache-Control: no-cache, must-revalidate")# HTTP/1.1 print("Expires: Sat, 26 Jul 1997 05:00:00 GMT") # Date in the past print("") f = open("/var/www/cgi-data/index.html", "r") for line in f: prin