cgi problems
Roger Upole
rupole at compaq.net
Mon May 22 21:06:36 EDT 2000
To keep the blank fields, use
formData=cgi.FieldStorage(keep_blank_values=1)
or they are automatically discarded.
To iterate over the values, iterate over the keys, eg
for field_name in formData.keys():
<do something with formData[field_name].value>
HTH
Roger Upole
"Rob Elder" <relder at omegabit.com> wrote in message
news:relder-2205001424540001 at s03.best1.net...
> Hello,
>
> I'm having inconsistencies and errors trying to use cgi.py.
>
> - cgi is imported
> - formData is set to cgi.FieldStorage()
>
> - len(formData) gives me the correct number of fields with data
> - formData['userID1].value gives a correct data value
> - formData.keys() gives a list of keys
>
> But
>
> - formData.values() gives an error message:
>
> Traceback (innermost last): File "C:\WebSite\cgi-shl\workingTest.py", line
> 29, in ? print formData.values() File "C:\Python152\Lib\cgi.py", line 888,
> in__getattr__ raise AttributeError, name AttributeError: values
>
> Also if some the fields on my test form are not filled in, the following
> error message is generated:
>
> Traceback (innermost last): File "C:\WebSite\cgi-shl\workingTest.py", line
20,
> in ? print formData['userID1'].value File "C:\Python152\Lib\cgi.py",
line907,
> in __getitem__ raise KeyError, key KeyError: userID1
>
> These two different problems relate back to values in the form. I don't
> know how to think about this. I have looked through the FAQs, docs and
> html. Maybe I am just missing the simplest things. Off-line all my
> dictionary calls work without any problems.
>
> -r
More information about the Python-list
mailing list