[Zope] cookie problem
Hung Jung Lu
hungjunglu@hotmail.com
Mon, 31 Jan 2000 15:43:40 PST
terry kerr <terr-@adroitnet.com.au> wrote:
>Umm...Yes, base64 didn't work for me, but neither did urllib.quote_plus()
>!!
>My pickled cookies have carrage returns in them, and unquoting the cookie
>just
>returns an error. The only method I have found so far is to string.replace
>all
>'\012' with "\\012".
I don't understand. You should use quote_plus() before setting
the cookie, and unquote_plus() after retrieving the cookie.
Steps:
(1) You have a pickled object.
(2) You use quote_plus() to transform the pickled object's
string to another string.
(3) You set the cookie with RESPONSE.setCookie()
(4) You can now retrieve the cookie by using
REQUEST.cookies['myCookieName']
(5) You unpickle the object.
If your steps are different from the above, then I don't know
what you are doing. :)
A '\012' in the pickled object's string will be mapped
to '%0a', which is perfectly fine to be stored as a cookie.
Perhaps your problem is that you are not reading/writing your
pickled file by using the binary tag as in 'rb' or 'wb'.
myFile = open('myFileName', 'rb')
myPickledString = myFile.read()
myFile.close()
....
myFile = open('myFileName', 'wb')
myPickledString = urllib.unquote_plus(
REQUEST.cookies['myCookieName'])
myFile.write(myPickledString)
myFile.close()
Anyway, please outline your steps so I can take a look
at why it isn't working for you.
regards,
Hung Jung
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com