Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'anyway.': 0.05; 'error:': 0.07; 'nicely': 0.07; 'python3': 0.07; 'subject:script': 0.09; 'python': 0.11; 'apache': 0.15; '"r")': 0.16; 'codec': 0.16; 'index.html': 0.16; 'log.': 0.16; 'ordinal': 0.16; 'renders': 0.16; 'subject:Unicode': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'passing': 0.19; 'aug': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'byte': 0.24; "i've": 0.25; 'script': 0.25; 'skip:" 30': 0.26; 'skip:" 40': 0.26; 'header:In-Reply-To:1': 0.27; 'gives': 0.31; "skip:' 10": 0.31; 'prints': 0.31; 'testing.': 0.31; 'file': 0.32; 'probably': 0.32; 'run': 0.32; '(most': 0.33; 'fri,': 0.33; 'skip:# 10': 0.33; 'message.': 0.35; 'subject:with': 0.35; "can't": 0.35; '+0200,': 0.36; 'done': 0.36; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'previous': 0.38; 'recent': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; 'skip:o 30': 0.61; 'complete': 0.62; 'url:index': 0.63; 'different': 0.65; 'skip:1 20': 0.65; 'charset:windows-1252': 0.65; '26,': 0.68; 'webpage': 0.68; 'jul': 0.74; '1997': 0.84; 'fine...': 0.84; 'findings': 0.91 Date: Sun, 17 Aug 2014 00:57:57 +0200 From: Dominique Ramaekers User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Unicode in cgi-script with apache2 References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408230368 news.xs4all.nl 2839 [2001:888:2000:d::a6]:53365 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76412 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 [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. >