cgi undefined?

Tyler Smith tyler.smith at
Sun Nov 4 22:51:47 CET 2007


I'm trying to learn how to use python for cgi scripting. I've got
apache set up on my laptop, and it appears to be working correctly.
I can run a basic cgi script that just outputs a new html page,
without reading in any form data, so I know that the basics are ok.
But when I try and use cgi.FieldStorage() I get the following errors
from cgitb:

A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred. 
    3 import cgitb; cgitb.enable()
    4 import cgi
    6 print """Content-type: text/html
cgi undefined
   12 <H1>Input values</H1>
   13 """
   14 form = cgi.FieldStorage()
   15 for key in form.keys():
   16    print '<p>key=%s, value=%s' % (key, form[key])
form undefined, cgi = <module 'cgi' from '/home/tyler/public_html/cgi-bin/'>, cgi.FieldStorage undefined

AttributeError: 'module' object has no attribute 'FieldStorage'
      args = ("'module' object has no attribute 'FieldStorage'",)

My form is:

<head><title>Tyler's webform</title></head>
<h1>Basic CGI form</h1>
<p>Here comes the form:
<form action="http://localhost/tycgi-bin/">
  <p>Enter some text here: <input type="text" name="text1"<br>

And the script is:

#! /usr/bin/python

import cgitb; cgitb.enable()
import cgi

print """Content-type: text/html

<TITLE>output of HTML from Python CGI script</TITLE>
<H1>Input values</H1>
form = cgi.FieldStorage()
for key in form.keys():
   print '<p>key=%s, value=%s' % (key, form[key])

print "</BODY></HTML>"

What am I doing wrong?



More information about the Python-list mailing list