: I wanted to know how i start the python script; what are the variables needed to be defined.
Oh, well the simplest way to write Python cgi scripts is like this:
The first line should be the "shebang":
On a *NIX system:
#!/usr/bin/python
On a Windows system:
#!C:\Python22\python.exe
Of course, the path may be different on your web server.
Then you need to print the header that tells your browser to expect html:
print 'Content-type: text/html\n'
Make sure you have the newline at the end!
After that, anything you print will be parsed by the browser as html. For example:
#!/usr/bin/python
print 'Content-type: text/html\n'
print """
<html>
<head>
<title>My first cgi script!</title>
<head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
"""
Then you just drop that script in the cgi-bin on your server and call it with a regular URL in a browser.
Debugging cgi is rather frustrating, but there is a way in python to make it much easier to find code errors. Just after the shebang line (which must be the first line of the file) put this:
import cgitb; cgitb.enable()
This imports the cgi traceback module. If any exceptions are raised by your script, you will get a pretty html display of the code and a description of the error and the line that caused it rather than the unhelpful "500: Internal Server Error".
infidel