I'm trying to use a for loop with a FieldStorage object and I get the
following error. Can you not treat it like a dictionary, or am I writing
the for loop incorrectly?
for item in form:
print item
# or print item.value
KeyError Python 2.2.1: /usr/bin/python
Fri Jun 2 15:12:36 2006
A problem occurred in a Python script. Here is the sequence of function
calls leading up to the error, in the order they occurred.
/kunden/homepages/7/d159103796/htdocs/labinfo.py
6 print 'content-type: text/html\n'
7
8 form = cgi.FieldStorag e(keep_blank_va lues=True)
9 for item in form:
10 print item
item undefined, form = FieldStorage(No ne, None,
[MiniFieldStorag e('firs...02116 '), MiniFieldStorag e('foreignAddre ss', '')])
/usr/lib/python2.2/cgi.py in __getitem__(sel f=FieldStorage( None, None,
[MiniFieldStorag e('firs...02116 '), MiniFieldStorag e('foreignAddre ss',
'')]), key=0)
548 if item.name == key: found.append(it em)
549 if not found:
550 raise KeyError, key
551 if len(found) == 1:
552 return found[0]
KeyError undefined, key = 0
KeyError: 0
__doc__ = 'Mapping key not found.'
__getitem__ = <bound method KeyError.__geti tem__ of
<exceptions.Key Error instance at 0x81633e4>>
__init__ = <bound method KeyError.__init __ of
<exceptions.Key Error instance at 0x81633e4>>
__module__ = 'exceptions'
__str__ = <bound method KeyError.__str_ _ of <exceptions.Key Error
instance at 0x81633e4>>
args = (0,)
following error. Can you not treat it like a dictionary, or am I writing
the for loop incorrectly?
for item in form:
print item
# or print item.value
KeyError Python 2.2.1: /usr/bin/python
Fri Jun 2 15:12:36 2006
A problem occurred in a Python script. Here is the sequence of function
calls leading up to the error, in the order they occurred.
/kunden/homepages/7/d159103796/htdocs/labinfo.py
6 print 'content-type: text/html\n'
7
8 form = cgi.FieldStorag e(keep_blank_va lues=True)
9 for item in form:
10 print item
item undefined, form = FieldStorage(No ne, None,
[MiniFieldStorag e('firs...02116 '), MiniFieldStorag e('foreignAddre ss', '')])
/usr/lib/python2.2/cgi.py in __getitem__(sel f=FieldStorage( None, None,
[MiniFieldStorag e('firs...02116 '), MiniFieldStorag e('foreignAddre ss',
'')]), key=0)
548 if item.name == key: found.append(it em)
549 if not found:
550 raise KeyError, key
551 if len(found) == 1:
552 return found[0]
KeyError undefined, key = 0
KeyError: 0
__doc__ = 'Mapping key not found.'
__getitem__ = <bound method KeyError.__geti tem__ of
<exceptions.Key Error instance at 0x81633e4>>
__init__ = <bound method KeyError.__init __ of
<exceptions.Key Error instance at 0x81633e4>>
__module__ = 'exceptions'
__str__ = <bound method KeyError.__str_ _ of <exceptions.Key Error
instance at 0x81633e4>>
args = (0,)