FAQ
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

Search Discussions

  • Bruno Desthuilliers at Nov 4, 2007 at 10:09 pm

    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.
  • Tyler Smith at Nov 4, 2007 at 11:08 pm

    On 2007-11-04, Dennis Lee Bieber wrote:
    '/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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 4, '07 at 9:51p
activeNov 4, '07 at 11:08p
posts3
users2
websitepython.org

People

Translate

site design / logo © 2022 Grokbase