Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76382 > unrolled thread

Unicode in cgi-script with apache2

Started byDominique Ramaekers <dominique@ramaekers-stassart.be>
First post2014-08-15 20:10 +0200
Last post2014-08-17 01:08 -0700
Articles 3 on this page of 23 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-15 20:10 +0200
    Re: Unicode in cgi-script with apache2 alister <alister.nospam.ware@ntlworld.com> - 2014-08-15 19:27 +0000
      Re: Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-17 00:36 +0200
        Re: Unicode in cgi-script with apache2 Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-17 02:50 +0000
          Re: Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-17 07:32 +0200
          Re: Unicode in cgi-script with apache2 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-17 17:50 +1000
            Re: Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-17 11:40 +0200
            Re: Unicode in cgi-script with apache2 wxjmfauth@gmail.com - 2014-08-17 03:05 -0700
            Re: Unicode in cgi-script with apache2 Peter Otten <__peter__@web.de> - 2014-08-17 13:04 +0200
            Re: Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-17 13:34 +0200
            Re: Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-17 14:02 +0200
              Re: Unicode in cgi-script with apache2 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-17 23:00 +1000
                Re: Unicode in cgi-script with apache2 wxjmfauth@gmail.com - 2014-08-17 08:56 -0700
            Re: Unicode in cgi-script with apache2 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-17 13:35 +0100
              Re: Unicode in cgi-script with apache2 Tony the Tiger <tony@tiger.invalid> - 2014-08-18 04:39 +0000
            Re: Unicode in cgi-script with apache2 Peter Otten <__peter__@web.de> - 2014-08-17 15:12 +0200
            Re: Unicode in cgi-script with apache2 Peter Otten <__peter__@web.de> - 2014-08-17 16:06 +0200
        Re: Unicode in cgi-script with apache2 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-17 15:54 +1000
    Re: Unicode in cgi-script with apache2 John Gordon <gordon@panix.com> - 2014-08-15 19:32 +0000
      Re: Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-17 00:39 +0200
    Re: Unicode in cgi-script with apache2 Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-16 16:40 +0000
      Re: Unicode in cgi-script with apache2 Dominique Ramaekers <dominique@ramaekers-stassart.be> - 2014-08-17 00:57 +0200
    Re: Unicode in cgi-script with apache2 wxjmfauth@gmail.com - 2014-08-17 01:08 -0700

Page 2 of 2 — ← Prev page 1 [2]


#76406

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-08-16 16:40 +0000
Message-ID<lso1hu$pra$2@dont-email.me>
In reply to#76382
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-data/index.html", "r")
> for line in f:
>      print(line,end='')
> 
> If I run the script in the terminal, it nicely prints the webpage
> 'index.html'.
> 
> If access the script through a webbrowser, apache gives an error:
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 1791: ordinal not in range(128)

Is this a message appearing in the apache error log or in the browser? If 
it is appearing in the browser, this is probably apache passing through a 
python error message.

Is this the complete error message?

What happens when you try and access http://[server]/cgi-data/index.html 
directly in a web browser? You may need to copy the file to a different 
directory to do this depending on the apache configuration.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#76412

FromDominique Ramaekers <dominique@ramaekers-stassart.be>
Date2014-08-17 00:57 +0200
Message-ID<mailman.13057.1408230368.18130.python-list@python.org>
In reply to#76406
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:11110] AH01215: Traceback (most recent call last):
[Sat Aug 16 23:12:42.158451 2014] [cgi:error] [pid 29327] [client 
119.63.193.196:11110] AH01215:   File "/var/www/cgi-python/index.html", 
line 12, in <module>
[Sat Aug 16 23:12:42.158473 2014] [cgi:error] [pid 29327] [client 
119.63.193.196:11110] AH01215:     for line in f:
[Sat Aug 16 23:12:42.158526 2014] [cgi:error] [pid 29327] [client 
119.63.193.196:11110] AH01215:   File 
"/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
[Sat Aug 16 23:12:42.158569 2014] [cgi:error] [pid 29327] [client 
119.63.193.196:11110] AH01215:     return codecs.ascii_decode(input, 
self.errors)[0]
[Sat Aug 16 23:12:42.158663 2014] [cgi:error] [pid 29327] [client 
119.63.193.196:11110] AH01215: UnicodeDecodeError: 'ascii' codec can't 
decode byte 0xc3 in position 1791: ordinal not in range(128)

If I access the file index.html directly from the brower, It renders fine...

I've done a lot of testing. I put my findings in a previous message.

Thanks anyway.

grz

Op 16-08-14 om 18:40 schreef 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-data/index.html", "r")
>> for line in f:
>>       print(line,end='')
>>
>> If I run the script in the terminal, it nicely prints the webpage
>> 'index.html'.
>>
>> If access the script through a webbrowser, apache gives an error:
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
>> 1791: ordinal not in range(128)
> Is this a message appearing in the apache error log or in the browser? If
> it is appearing in the browser, this is probably apache passing through a
> python error message.
>
> Is this the complete error message?
>
> What happens when you try and access http://[server]/cgi-data/index.html
> directly in a web browser? You may need to copy the file to a different
> directory to do this depending on the apache configuration.
>

[toc] | [prev] | [next] | [standalone]


#76417

Fromwxjmfauth@gmail.com
Date2014-08-17 01:08 -0700
Message-ID<f183f1fc-4095-4a86-b1da-305feeffd8de@googlegroups.com>
In reply to#76382
Le vendredi 15 août 2014 20:10:25 UTC+2, Dominique Ramaekers a écrit :
> 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:
> 
>      print(line,end='')
> 
> 
> 
> If I run the script in the terminal, it nicely prints the webpage 
> 
> 'index.html'.
> 
> 
> 
> If access the script through a webbrowser, apache gives an error:
> 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 
> 
> 1791: ordinal not in range(128)
> 
> 
> 
> I've done a hole afternoon of reading on fora and blogs, I don't have a 
> 
> solution.
> 
> 
> 
> Can anyone help me?
> 
%%%%%%%%%

Your (typical) problem is not unicode, the OS or Python.

The origin of the problem is a different nature and should
be understood "globally" in a different way.

Your job is a succession of single processes/steps,

input -> process -> output,

your are manipulating with an engine: Python. The process
may be: reading a file, sending the output to a terminal, CGI,
sending to "Apache", ...
What happens, is that the coding of the characters of the
input/output of every process is or may be different and
may lead to conflicts.
The rule of the game is to use the engine (Python, in
that case) to ensure the coding of the output matches
the coding of the input of the next process.

Schematically:

input1 -> process1 -> output1 -> [eventually "transcode"] ->
input2 -> process2 -> output2 -> ....

Attempting to find a "coding common denominator", (eg. by
tweaking the platform coding or the engine coding) may fail,
because by nature a single process may require a specific
coding, eg. utf-8 for the "Apache input", which can be different
from the coding required or used in another process.

When you say, "I read a file, display it and it just work",
it means in reality:
The coding output of the "read a file process" does correspond
to the "input coding of the display process". It works, because,
by chance, the output/input coding matches in a transparent
way.

Keep in mind, the coding of characters is a job "per se". It
is independent from any progamming language, any platform ...

jmf

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web