[Zope] Cookies and dictionaries

Andreas Jung andreas at andreas-jung.com
Fri Feb 6 15:27:42 EST 2004


Maybe because cookies are stored in a dedicated dict in the REQUEST object.
Check the implementation in HTTPRequest.py.

-aj

--On Freitag, 6. Februar 2004 14:19 Uhr -0600 Kashif Jabbar 
<kjabbar at ssidecisions.com> wrote:

> I changed the script as follows:
>
>###
> request = container.REQUEST
> response =  request.RESPONSE
>
> dic = {'filter':'yes'}
> response.setCookie('myCookie', dic)
> if request.has_key('myCookie'):
>     mydic = request['myCookie']   <-------- note the change
>     print mydic['filter']
>
> return printed
>###
>
> and I still get the same error.
>
>
> Andreas Jung wrote:
>
>> use request[somekey] and *not* request.somekey
>> -aj
>>
>> --On Freitag, 6. Februar 2004 14:01 Uhr -0600 Kashif Jabbar
>> <kjabbar at ssidecisions.com> wrote:
>>
>>> Hello,
>>>
>>> I am trying to store a dictionary in a cookie which I would like to
>>> retrieve later and use. A test python script is as follows:
>>>
>>> ##########
>>> request = container.REQUEST
>>> response =  request.RESPONSE
>>>
>>> dic = {'filter':'yes'}
>>> response.setCookie('myCookie', dic)
>>> if request.has_key('myCookie'):
>>>     mydic = request.myCookie
>>>     print mydic['filter']
>>>
>>> return printed
>>> ###########
>>>
>>> When the script is run I get an error:
>>>
>>>> *Error Type: TypeError*
>>>> *Error Value: sequence index must be integer*
>>>
>>>
>>> It seems that the dictionary is returned as a string. How can I cast
>>> this
>>> string to a dictionary type?
>>>
>>> Thanks.
>>> Kashif
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Zope maillist  -  Zope at zope.org
>>> http://mail.zope.org/mailman/listinfo/zope
>>> **   No cross posts or HTML encoding!  **
>>> (Related lists -  http://mail.zope.org/mailman/listinfo/zope-announce
>>>  http://mail.zope.org/mailman/listinfo/zope-dev )
>>
>>
>>
>>
>>
>>
>>
>
>
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )







More information about the Zope mailing list