Using Python

I’m having problems getting a CGI script to work with python. If I run the following script, it works fine:

echo Content-Type: text/plain

However if I try to use python (with the same file permissions)


causes an internal server error (below). Am I listing python correctly? This seems to be what the knowledgebase recommends.

Any suggestions?


  • lars

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Hi Lars,

Most likely you need to make the file permissions 755, AS WELL as the directory it’s in. We use suexec to make CGI scripts run as the user themselves, rather than as an apache user, so as a security measure the files nor the directory they’re in can be world or group writable.

You can also check your logs (/home/username/logs/ for more info if that doesn’t fix it!


Thanks for the feedback. However, I think I’ve eliminated this as the source of the problem. The two examples I’ve given are from the same file. I’m just changing the text within the file so the permissions are the same. One version works (without python) the other fails.

Any other thoughts?

  • Lars

What are the contents of your python test script? Does it work properly if you run it from the command line?

Here’s how I’m testing it:
lynx -dump

The file works fine:

print "Content-Type:text/plain\n\n"

This file gives me an internal server error:


I’m not sure why.

Apache expects to see HTTP headers in the beginning of the output - if you leave them out Apache will tell you so in the log files.

:cool: Perl / MySQL / HTML+CSS

Ok - so dumb question then. What do I need to add?

I’m using a cgi script I downloaded that was provided for a wiki.

Thanks for helping a newbie.