[mod_python] Can i have both Marshal and Signed Cookies withPublisher?

Graham Dumpleton grahamd at dscpl.com.au
Sun Oct 29 16:09:51 EST 2006

That would be understandable. The Cookie.get_cookies() expects you
to supply a class type and since there are multiple cookies stored of
differing types then the class type supplied may not be able to unpack
all of them.

There probably needs to be a Cookie.get_cookie() so you can say that
you only want to get a specific cookie by name. Not sure I understand
why there isn't one already unless I am missing something.

Besides writing your own version of Cookie.get_cookie(), the only other
way of getting around the problem for now is to set the 'path' attribute
of the cookies so that the cookies only get delivered to their respective
applications. But then, even that isn't necessarily going to help in all
cases because sessions use cookies as well, so it you want to use a
marshalled cookie in the same context as a session is used you are
similarly going to have a problem if the session is signed.


Clodoaldo Pinto Neto wrote ..
> If i set both a Signed and a Marshal cookie and try to retrieve the
> Marshal one using the Publisher i get this error:
> ----------------------------------------
> Mod_python error: "PythonHandler mod_python.publisher"
> Traceback (most recent call last):
>   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
> 299, in HandlerDispatch
>     result = object(req)
>   File "/usr/lib/python2.4/site-packages/mod_python/publisher.py",
> line 213, in handler
>     published = publish_object(req, object)
>   File "/usr/lib/python2.4/site-packages/mod_python/publisher.py",
> line 412, in publish_object
>     return publish_object(req,util.apply_fs_data(object, req.form, req=req))
>   File "/usr/lib/python2.4/site-packages/mod_python/util.py", line
> 439, in apply_fs_data
>     return object(**args)
>   File "/var/www/html/teste/python/publisher/marshalcookie.py", line
> 10, in index
>     marshal_cookies = Cookie.get_cookies(
>   File "/usr/lib/python2.4/site-packages/mod_python/Cookie.py", line
> 350, in get_cookies
>     return Class.parse(cookies, **kw)
>   File "/usr/lib/python2.4/site-packages/mod_python/Cookie.py", line
> 252, in parse
>     c.unmarshal(secret)
>   File "/usr/lib/python2.4/site-packages/mod_python/Cookie.py", line
> 280, in unmarshal
>     self.value = marshal.loads(base64.decodestring(self.value))
>   File "/usr/lib/python2.4/base64.py", line 319, in decodestring
>     return binascii.a2b_base64(s)
> Error: Incorrect padding
> ---------------------------------------------
> If the Signed cookie is deleted then the Marshal cookie can be
> retrieved with no errors.
> The scripts that trigger the error are:
> Set and retrieve the Signed cookie:
> http://webpython.codepoint.net/mod_python_publisher_cookies_signed
> Set and retrieve the Marshal cookie:
> http://webpython.codepoint.net/mod_python_publisher_cookies_marshal
> I'm just building that tutorial. BTW i would appreciate to have it
> corrected by the experts.
> I tested in Firefox and Opera 9.02. FC5, mod_python 3.2.8, Apache
> 2.2.2.
> Regards, Clodoaldo Pinto Neto
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list