Problems with running Python CGI Scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eddiefisher41
    New Member
    • Jun 2007
    • 15

    Problems with running Python CGI Scripts

    Hey guys.
    Im having problems running a python cgi. Im using the example code from:
    http://www.python.org/doc/essays/ppt...ast/sld041.htm 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:

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>A Typical HTML form</title></head>
    <body>
    <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='http://www.fisherphoto graphics.co.uk/testcgia.pyc'>
    <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'>
    </form></body></html>

    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:

    #!/usr/local/bin/python
    import cgi

    def main():
    print "Content-type: text/html\n"
    form = cgi.FieldStorag e()
    if form.has_key("f irstname") 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>"
    else:
    print "<h1>Error! Please enter first name.</h1>"

    main()

    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
Working...