Can't seem to get python to work

Posted by Justin Johnson on Server Fault See other posts from Server Fault or by Justin Johnson
Published on 2010-03-15T19:35:25Z Indexed on 2010/03/15 19:40 UTC
Read the original article Hit count: 457

Filed under:

I'm just starting out in Python. The Python interpreter works from the command line (I have 2.4.3), but I can't seem to get Apache to execute Python scripts. All I end up with is a blank screen and nothing in the Apache error logs.

I enabled Python via the Plesk control panel. Here's the snippet that was generated in the httpd.include:

<Files ~ (\.py$)>
    SetHandler python-program
    PythonHandler   mod_python.cgihandler
</Files>

My test script is one of the examples that comes with the Python downloads at http://python.org/download/

#!/usr/local/bin/python

"""CGI test 1 - check server setup."""

# Until you get this to work, your web server isn't set up right or
# your Python isn't set up right.

# If cgi0.sh works but cgi1.py doesn't, check the #! line and the file
# permissions.  The docs for the cgi.py module have debugging tips.

print("Content-type: text/html")
print()
print("<h1>Hello world</h1>")
print("<p>This is cgi1.py")

That wasn't working, so I changed #!/usr/local/bin/python to #!/usr/bin/python which is what which python tells me but the results were the same.

Like I said, I'm ending up with a blank page. No errors that I know of, unless I'm checking the wrong error log (I'm checking the Apache error log). I'm on a MediaTemple (dv) running CentOS.

© Server Fault or respective owner

Related posts about python