cgi undefined?
Tyler Smith
tyler.smith at mail.mcgill.ca
Sun Nov 4 16:51:47 EST 2007
Hi,
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.
/home/tyler/public_html/cgi-bin/cgi.py
2
3 import cgitb; cgitb.enable()
4 import cgi
5
6 print """Content-type: text/html
cgi undefined
/home/tyler/public_html/cgi-bin/cgi.py
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.py'>, cgi.FieldStorage undefined
AttributeError: 'module' object has no attribute 'FieldStorage'
args = ("'module' object has no attribute 'FieldStorage'",)
My form is:
<html>
<head><title>Tyler's webform</title></head>
<body>
<h1>Basic CGI form</h1>
<p>Here comes the form:
<form action="http://localhost/tycgi-bin/cgi.py">
<p>Enter some text here: <input type="text" name="text1"<br>
</form></body></html>
And the cgi.py script is:
#! /usr/bin/python
import cgitb; cgitb.enable()
import cgi
print """Content-type: text/html
<HTML><HEAD>
<TITLE>output of HTML from Python CGI script</TITLE>
</HEAD>
<BODY>
<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?
Thanks,
Tyler
More information about the Python-list
mailing list