Using Python

apps

#1

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

#!/bin/sh
echo Content-Type: text/plain
echo
echo IT WORKS

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

#!/usr/bin/python

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

Any suggestions?

Thanks

  • lars

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@teachtown.com 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.


#2

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/domain.com/http/error.log) for more info if that doesn’t fix it!

josh!


#3

Josh,
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

#4

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


#5

Here’s how I’m testing it:
lynx -dump http://www.mydomain.com/test.cgi

The file works fine:

#!/usr/bin/python
print "Content-Type:text/plain\n\n"
print “IT WORKS WITH PYTHON!\n”

This file gives me an internal server error:

#!/usr/bin/python

I’m not sure why.


#6

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


#7

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.