beginner python cgi question

Brandon Boles email at nowhere.foo
Sat Dec 13 11:08:59 CET 2003


Hi folks,

I am trying to learn python, and have a form processing script giving me
this error:

Traceback (most recent call last):
  File "inquiry", line 16, in ?
    Address=fields["address"].value
  File "/usr/local/python2.2/lib/python2.2/cgi.py", line 550, in __getitem__
    raise KeyError, key
KeyError: address

This is the snippet of code the error is referring to:

...snip...
fields=cgi.FieldStorage()
    if (fields.has_key("name") and fields.has_key("emailaddr")):
        SenderName=fields["name"].value
        Address=fields["address"].value
        City=fields["city"].value
        State=fields["state"].value
...snip...

I think what the problem is that if my form does not have one of the
fields (except 'name' and 'emailaddr') with data in it, I get this error. 
What is the best way to fix this?

Please be kind, this is my first attempt at python.  Thanks for the help!

Brandon




More information about the Python-list mailing list