By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

Problems with running Python CGI Scripts

P: 15
Hey guys.
Im having problems running a python cgi. Im using the example code from: as writen by Van Rossum himself

I can get the script to run the python script but all that happens is that the black python box appears then disapears, the html that the python scripts should generate is never output.

My html is:

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>A Typical HTML form</title></head>
<p align="center"><u><b><font size="5">A Typical HTML form</font></b></u></p>
<p align="center"><font size="1" color="#FF0000">*Test CGI script and HTML to
test server for correct running of python cgi scripting</font></p>
<form method='GET' action=''>
<p align="center">Your First Name:
<input type='text' name='firstname' size="20">
<p align="center">Your Last Name: <input type='text' name='lastname' size="20">
<p align="center">Click here to submit form: <input type='submit' value='Yeah!'>
<input type='hidden' name='session' value='1f9a2'>

This is calling the pyc file of the python script. I dont understand why if i call the py file itself all i get returned is the plain text of the python file.

The python script is:

import cgi

def main():
print "Content-type: text/html\n"
form = cgi.FieldStorage()
if form.has_key("firstname") and form["firstname"].value != "":
#if form has an object called firstname and the value is not an empty string
print "<h1>Hello", form["firstname"].value, "</h1>"
print "<h1>Error! Please enter first name.</h1>"


If you need to see what happens then follow this link:

The python file has come directly from the example so i must me doing something wrong. I have all the correct permissions etc
Thanks very much
Ed Fisher
Sep 2 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.