cgi undefined?

T

Tyler Smith

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
 
B

Bruno Desthuilliers

Tyler Smith a écrit :
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 (snip)
form undefined, cgi = <module 'cgi' from '/home/tyler/public_html/cgi-bin/cgi.py'>, cgi.FieldStorage undefined (snip)
AttributeError: 'module' object has no attribute 'FieldStorage' (snip)

What am I doing wrong?

Not paying enough attention to the error message, perhaps ? Your script
is named cgi.py. rename it and you should be fine.
 
D

Dennis Lee Bieber

On 04 Nov 2007 21:51:47 GMT, Tyler Smith <[email protected]>
declaimed the following in comp.lang.python:

said:
4 import cgi

said:
form undefined, cgi = <module 'cgi' from '/home/tyler/public_html/cgi-bin/cgi.py'>, cgi.FieldStorage undefined

<snip>

'/home/tyler/public_html/cgi-bin/cgi.py'
^^^^^^

Very simple -- you named YOUR handler "cgi". So when it does "import
cgi" it is importing itself...

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
T

Tyler Smith

'/home/tyler/public_html/cgi-bin/cgi.py'
^^^^^^

Very simple -- you named YOUR handler "cgi". So when it does "import
cgi" it is importing itself...

Of course. I knew it must be something dumb. Thanks!

Tyler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top