Zope Unsubscriptable object error
Hi, 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 Traceback (innermost last): File C:\PROGRA~1\ZopeDev\lib\python\ZPublisher\Publish.py, line 150, in publish_module File C:\PROGRA~1\ZopeDev\lib\python\ZPublisher\Publish.py, line 114, in publish File C:\PROGRA~1\ZopeDev\lib\python\Zope\__init__.py, line 159, in zpublisher_exception_hook (Object: clone_order) File C:\PROGRA~1\ZopeDev\lib\python\ZPublisher\Publish.py, line 98, in publish File C:\PROGRA~1\ZopeDev\lib\python\ZPublisher\mapply.py, line 88, in mapply (Object: clone_order_submissionAction) File C:\PROGRA~1\ZopeDev\lib\python\ZPublisher\Publish.py, line 39, in call_object (Object: clone_order_submissionAction) File C:\PROGRA~1\ZopeDev\lib\python\OFS\DTMLMethod.py, line 127, in __call__ (Object: clone_order_submissionAction) File C:\PROGRA~1\ZopeDev\lib\python\DocumentTemplate\DT_String.py, line 473, in __call__ (Object: clone_order_submissionAction) File C:\PROGRA~1\ZopeDev\lib\python\DocumentTemplate\DT_Util.py, line 159, in eval (Object: checkOrderDatabase(idlist)) (Info: idlist) File <string>, line 2, in f 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) What is going on here?? Zope won't let me subscript a tuple or a list? If I modify the sql such that it returns more than one column, then the subscripting calls work. Grrr. Thanks, Mark Here is the code for the external method: import DCOracle2 as dco # Begin Main Method #################################### def main (idlist): finalresult="" dCon = dco.connect("scott/tiger@devbase") dCur = dCon.cursor() for id in idlist: sql = "SELECT status from ordered where id ='"+ str(id)+"'" dCur.execute(sql) foo = dCur.fetchone() status = str(foo[0]) finalresult = finalresult+"ID: "+str(id)+" Status: "+status+"<BR>" return "id list is "+str(idlist) +"<BR>"+finalresult
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
Thanks for the reply, Dieter. Your reply gave me confidence that External Methods are truely autonomous, so I went back and checked. I'm embarrassed to say the code does work, it was my test query that was generating the error. One of the id's I was checking for was not in the database. This returns the 'None' object, which of course, is not subscriptable. I'm glad to have this cleared up. Thanks for the help, Mark Evans
From: Dieter Maurer <dieter@handshake.de> Date: Sun, 21 Jul 2002 22:59:40 +0200 To: Mark Evans <wavecat01@attbi.com> Cc: <zope-db@zope.org>, <zope@zope.org> Subject: Re: [Zope-DB] Zope Unsubscriptable object error
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
participants (2)
-
Dieter Maurer -
Mark Evans