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