cgi integration question 2

Gerhard Häring gerhard.haering at gmx.de
Sun Oct 20 18:46:32 EDT 2002


* Ken <ken at hotmail.com> [2002-10-21 08:02 +1000]:
> Hi, there isn't such module call cgitb
> Traceback (most recent call last):
>   File "chessboard.cgi", line 7, in ?
>     import os, cgi, cgitb
> ImportError: No module named cgitb

cgitb is available in Python 2.2 and later.

> The python code is here:
> http://www.ug.cs.usyd.edu.au/~keho/comp3204/chessboard.txt and
> http://www.ug.cs.usyd.edu.au/~keho/comp3204/chessboard.cgi
> 
> The C++ test code is here:
> http://www.ug.cs.usyd.edu.au/~keho/comp3204/test02.cc

Works fine for me if I install it all locally. It prints this:

lines: ['12\n', '13\n', '33\n', '31\n', '32\n', '22\n', '21\n', '23\n', '11\n']
Content-type: text/html results: ['12\n', '13\n', '33\n', '31\n', '32\n', '22\n', '21\n', '23\n', '11\
n']
                               +-----------------+                             
                               |  2  |  8  |  3  |                             
                             3 |-----+-----+-----|                             
                             2 |  1  |  6  |  5  |                             
                             1 |-----+-----+-----|                             
                               |  9  |  7  |  4  |                             
                               +-----------------+                             
                                 A     B     C                                 

You might want to fix the print statements so you get something like:

    Content-type: text/html

    <html>
    [...]

Note the empty line between the HTTP headers (here only one line, the
Content-type line) and the HTTP body.

> What did I do wrong to constantly get that broken pipe error?
> Traceback (most recent call last): File
> "/usr/cs3/keho/lib/html/comp3204/chessboard.cgi", line 143, in ?
> outf.close() IOError: [Errno 32] Broken pipe

Most probably a permission problem of some sort. I'd copy the C++
executable in the same directory as the Python script, but still use the
full path in os.popen2 or use "./knight" as a relative path. Also check
the permissions are ok (i. e. the user that runs the cgi scripts can
execute the C++ executable).

-- Gerhard




More information about the Python-list mailing list