having serious problems getting a python CGI to work

J

John Draper

I am having a lot of problems trying to get a Python CGI to run.
I have included 3 parts...

1) A simple stripped down python module.
2) An output of what I get when I do: python index.py
(which not suprisingly should generate HTML output, and it does)
3) And the "error_log" output from the "server error" I get when I run
it
by typing in: http://localhost/cgi-bin/index.py

I'm running this on a Mac OS-X 10.3.3 Server.

This is a snippit of the source module

#!/usr/bin/python2.3
#Last revision 2003-08-19
#"index.py": page/dispatcher/security envelope for all Python routines

import cgitb; cgitb.enable()
import sys
sys.stderr=sys.stdout
from cgi import escape
from os import environ

print """Content-Type: text/html; charset="iso-8859-1"\n"""
try:
cmd=environ["PATH_INFO"]+"?"+environ["QUERY_STRING"]
except:
cmd="/welcome"

#Warning: Keep this text short so that the "<html " element is not
pushed
# past the first 256 bytes of the output (not counting HTTP header).
print """<!--This is my test web page with frames -->
"""
if cmd[:2]!="//":
print """<?xml version="1.0" encoding="iso-8859-1"?>"""
#The presense of a valid DOCTYPE line breaks IE 6.0 and Mozilla,
# but omitting it puts them into quirks/compatibility mode.
# Specifically, it adds a white border on the frame under IE 5.1
(Mac).
#print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">"""
print """<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>My Test Page</title>
</head>"""
#FRAMESET has no border attribute, however it helps IE and Opera.
print """ <frameset rows="132,*" border="0">
<frame src="/CGI-Executables/index.py//toppane" frameborder="0"
name="topframe" noresize="noresize" scrolling="no" />
<frame src="/CGI-Executables/index.py/%s" frameborder="0"
name="bottomframe" />
<noframes>
<body>This requires frames to use</body>
</noframes>
</frameset>


This is what I would type to first test the CGI module.
And as expected I get the xml code back, as you see below.

sh-2.05b# python index.py
Content-Type: text/html; charset="iso-8859-1"

<!--This is my test web page with frames -->

<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>My Test Page</title>
</head>
<frameset rows="132,*" border="0">
<frame src="/CGI-Executables/index.py//toppane" frameborder="0"
name="topframe" noresize="noresize" scrolling="no" />
<frame src="/CGI-Executables/index.py//welcome" frameborder="0"
name="bottomframe" />
<noframes>
<body>This requires frames to use</body>
</noframes>
</frameset>
</html>

This is the output of the apache "error_log" file I get.

error] (2)No such file or directory: exec of
/Library/WebServer/CGI-Executables/index.py failed
[Mon May 31 22:05:09 2004] [error] [client 192.168.1.250] Premature end
of script headers: /Library/WebServer/CGI-Executables/index.py

-------

NOTE: I Set the chmod flags to 755 - made sure execute privelages are
set.
Running as "root".

Question: What does a "Premature end of script headers" mean. This
message is very
confusing. What would normally cause this?

Why would I get: "No such file or directory" exec of .... failed? I
DID set the
"x" bits on the file. What ELSE could I be doing wrong?

John
 
R

Roland Heiber

John said:
print """Content-Type: text/html; charset="iso-8859-1"\n"""

You need \n\n after the header.

import sys
sys.stdout.write("""Content-Type: text/html;charset="iso-8859-1"\n\n""")

Try this ... if the webserver is executing the cgi's using
suexecusergroup, take a look at the suexec log in your log-dir.

HtH, Roland
 
K

Kyler Laird

John Draper said:
error] (2)No such file or directory: exec of
/Library/WebServer/CGI-Executables/index.py failed

I suspect that this has little to do with Python.

Can you run a shell script through CGI on that system?
#!/bin/sh

echo Content-type: text/plain
echo
date

If you can get that far, we can easily debug the Python execution.
(Is there "strace" for MacOS?)

--kyler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top