1

Edit: OS is CentOS 5

I installed Python 2.5.5 and am trying to run some Python scripts via the browser.

Honestly, I have not worked with Python before. I attempted to load the python module into Apache, but it is already loaded and was skipped. I also confirmed that I can run python scripts from my command line if I make them executable.

However when I put "http://www.example.com/test.py" into my browser, it returns unparsed HTML as follows:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
 root@localhost and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at www.example.com Port 80</address>
</body></html>

I also have the following in my httpd.conf file.

AddHandler cgi-script .py

I am stumped as I do not know where to look from here. Does this ring a bell for anyone? Hopefully nothing too obvious that I am overlooking here...

Thank you in advance.

Edit: Found the following in the Apache error_log.

[Fri Feb 26 19:58:38 2010] [error] [client xxx.xxx.xxx.xxx] (13)Permission denied: exec of 'test.py' failed
[Fri Feb 26 19:58:38 2010] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: test.py
[Fri Feb 26 20:04:56 2010] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
3
  • What does your Apache error log say? If you are using SuExec: What does your suexec.log say? Both files should be found in /var/log/apache2/.
    – joschi
    Feb 26, 2010 at 10:59
  • I posted that information into my original message.
    – Structure
    Feb 26, 2010 at 11:09
  • FYI. You don't need mod_python if all you want to do is write CGI scripts using Python. Mar 2, 2010 at 10:16

3 Answers 3

1

Error 13 from apache indicates a filesystem permissions problem.
Is SElinux enabled? (what's the output of "ls -laZ test.py")

I doubt it's a problem with ScriptAlias or AddHandler/ExecCGI (either of which will get apache to execute scripts) - since you're getting a 500 error and not the python source apache is clearly trying to execute the file.

6
  • -rw-r--r-- user user test.py
    – Structure
    Mar 1, 2010 at 1:55
  • Above is the output. So far as I can tell, SElinux is installed but not enabled on this machine. (rental server, not exactly sure)
    – Structure
    Mar 1, 2010 at 2:01
  • Ah, chmod a+x that script. As an aside, cat /etc/sysconfig/selinux or sestatus will tell you SElinux status. If SElinux is not enabled then... Mar 1, 2010 at 2:16
  • SELINUX=disabled, also, I ran chmod a+x but to no avail. I am going to take a look Apache permissions, etc.
    – Structure
    Mar 1, 2010 at 3:10
  • Wait, I didn't notice this before... AddHandler python-program .py (not cgi-script) Also, try renaming your script - python has a builtin module "test". Mar 1, 2010 at 3:24
1

I've only ever used mod_python for a Trac install and they provide fairly explicit instructions for their application.

However, while we were testing mod_python, I found this article helpful - you may too.

0
1

Apache will only execute files that are located in designated cgi-bin directories. Everything else is considered content that is passed to the viewer. Your root directory isn't, and shouldn't, be marked as such.

Use the ScriptAlias <url-path> <directory> directive to set your cgi-bin directories. eg: ScriptAlias /cgi-bin/ /webroot/cgi-bin/. Copy your scripts there, then call http://www.example.com/cgi-bin/test.py. That should work for you.

1
  • I configured the ScriptAlias as follows: ScriptAlias /cgi-bin/ /webroot/test/ Then I copied my script to that directory and called it from the browser, but the same error occured.
    – Structure
    Mar 1, 2010 at 1:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .