473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

having serious problems getting a python CGI to work

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


Jul 18 '05 #1
3 3128
John Draper wrote:
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
Jul 18 '05 #2
John Draper <li***@webcrunchers.com> writes:
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
Jul 18 '05 #3
In article <dt************@lairds.us>,
Kyler Laird <Ky***@news.Lairds.org> wrote:
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rami A. Kishek | last post by:
Hi - this mysterious behavior with shelve is just about to kill me. I hope someone here can shed some light. First of all, I have this piece of code which uses shelve to save instances of some...
7
by: Zoo Keeper | last post by:
>>> class foo(BWindow.BWindow): ... pass ... Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: base is not a class object Not entirely sure what the message means...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
14
by: Gotisch | last post by:
Hi, we are currently writing an mostly singlethreaded (game)server application in c#. But we are encountering problems with the Garbage Collector: After a certain time but also apparently...
8
by: pbd22 | last post by:
hi. i have spent the past week (i am afraid) trying to get the below script for uploading files via a hidden iframe to work. i have narrowed down my problem to the possibility that IE doesnt...
69
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of...
15
by: John Nagle | last post by:
I've been installing Python and its supporting packages on a dedicated server with Fedora Core 6 for about a day now. This is a standard dedicated rackmount server in a colocation facility,...
9
by: chadlupkes | last post by:
I'm getting NULLs where there shouldn't be. Any help is appreciated. Here are the tables: precinct Field Type Null Key Default Extra id smallint(6) PRI...
6
by: rh0dium | last post by:
Hi Experts!! I am trying to get the following little snippet to push my data to the function func(). What I would expect to happen is it to print out the contents of a and loglevel. But it's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.