[Zope-DB] Zope Unsubscriptable object error

Dieter Maurer dieter@handshake.de
Sun, 21 Jul 2002 22:59:40 +0200


Mark Evans writes:
 > I am having problems with an Unsubscriptable object error in Zope when the
 > returned tuple only contains one element.  The error goes away if the tuple
 > has 2 or more elements.  Any advice would be greatly appreciated.  See
 > details below.
 > Thanks in advance,
 > Mark
 > 
 > The following works in the python 2.1 interpreter:
 > 
 > >>> import DCOracle2 as dco
 > >>> d = dco.connect("scott/tiger@devbase")
 > >>> c = d.cursor()
 > >>> sql = "select status from ordered"
 > >>> c.execute(sql)
 > 1
 > >>> foo = c.fetchone()
 > >>> print foo
 > ['yes']
 > >>> print foo[0]
 > yes
 > >>>
 > 
 > When this is run as an external method in Zope, everything works, unless you
 > do
 > foo[0].  Then you get the error:
 > 
 > Zope Error
 > 
 > 
 > Zope has encountered an error while publishing this resource.
 > 
 > 
 > Error Type: TypeError
 > Error Value: unsubscriptable object
 > ...
 >   File 
 > C:\PROGRA~1\ZopeDev\lib\python\Products\ExternalMethod\ExternalMethod.py,
 > line 198, in __call__
 >     (Object: checkOrderDatabase)
 >     (Info: ((['1234A', '5678B'],), {}, None))
 >   File C:\Program Files\ZopeDev\Extensions\checkOrderDatabase.py, line 29,
 > in
 > main
 > TypeError: (see above)
You are sure, line 29 is "print foo[0]"?
Maybe, the error is somewhere else?

 > Zope won't let me subscript a tuple or a list? 
Inside an External Method, Zope does nothing to your Python code.
It should ran exactly as outside of Zope.


Dieter