Python CGI checklist

From XPUB & Lens-Based wiki
Revision as of 11:09, 13 May 2013 by Michael Murtaugh (talk | contribs) (Michael Murtaugh moved page PythonCGIChecklist to Python CGI Checklist)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Python CGI Checklist

Checklist for Developing Python CGI Scripts

  1. Save the file with the extension ".cgi"
2. Seeing the source code? Make sure you are viewing the script via the webserver. In other words, the URL should look like:
: http://localhost/~YOURUSERNAME/script.cgi
not:
: file://Users/YOURUSERNAME/Sites/script.cgi

If this doesn't work, make sure your webserver is running (Mac OS X: System Preferences, Sharing, Personal Web Sharing should be switched on).

3.#3 First line of the file should be the "shebang" telling the system (Apache) how to run the script (in other words which language it is).
#!python numbers=off
#!/usr/bin/python
4.#4 Permissions must be set to "world-executable".
: chmod 705 myscript.cgi
<!--# OR
-->
: chmod +x myscript.cgi
or simply
: chmod 705 *.cgi
<!--# OR
-->
: chmod +x *.cgi
to enable all the files (in the current directoy) that end in ".cgi"


5.#5 To enable errors to be displayed in the browser, add the following lines to the top of your script:
#!python numbers=off
import cgitb; cgitb.enable()
6.#6 Internal Server Error? Ensure the first thing that gets printed is the HTML header:
#!python numbers=off
print "Content-type: text/html"
print
7.#7 Still an error? Check the webserver's error log. From the terminal in Mac OS X, type:
tail /var/log/httpd/error_log

or (gentoo/apache2):

tail /var/log/apache2/error_log