[Zope-DB] Zope Unsubscriptable object error
Mark Evans
wavecat01@attbi.com
Mon, 22 Jul 2002 08:42:32 -0700
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