Hi everyone,
I figured out what I was doing wrong. From what I can see you need to
"fully create" the response cookie whenever you want to overwrite the
values you read from request cookie.

So I modified my code as follows and it worked:

if not request.cookies.has_key('elocookie'):
    mu = MU
    phi = PHI
    sigma = SIGMA
else:
    value = request.cookies['elocookie'].value
    logger.debug('read ELO cookie %s'%str(value))
    mu,phi,sigma = [float(v) for v in
value.replace('(','').replace(')','').split(',')]


logger.debug("retrieved elo %s %s %s"%(mu,phi,sigma))

... #calculate mu,phi,sigma

response.cookies['elocookie'] = (mu,phi,sigma)
response.cookies['elocookie']['expires'] = 72 * 3600
response.cookies['elocookie']['path'] = '/'
logger.debug("new cookie elo %s %s %s"%(mu,phi,sigma))

Thanks, Jon.

On Sat, Apr 18, 2020 at 8:33 PM Jon Subscripted <[email protected]>
wrote:

> Hi everyone,
> I'm facing some problems handling cookies. I need to store and update a
> value for non-auth users.
> I need to do it throughout the session (this could be done with session
> cookies) but also between different sessions. That's why I decided to use
> cookies.
>
> I tried to follow web2py books' instructions (
> http://www.web2py.com/books/default/chapter/29/04/the-core#Cookies ), but
> it does not work as expected.
>
> My problem is that I just succeed to set the cookie value properly the
> first time. My guess is that I do not fully understand the request/response
>
> ````
> if not request.cookies.has_key('elocookie'):
>     logger.debug("create ELO cookie")
>     response.cookies['elocookie'] = (MU,PHI,SIGMA)
>     response.cookies['elocookie']['expires'] = 72 * 3600
>     response.cookies['elocookie']['path'] = '/'
> else:
>     value = request.cookies['elocookie'].value
>     logger.debug('read ELO cookie %s'%str(value))
>     mu,phi,sigma = [float(v) for v in
> value.replace('(','').replace(')','').split(',')]
>
>
> logger.debug("retrieved elo %s %s %s"%(mu,phi,sigma))
> ... #calculate mu,phi,sigma
>
> response.cookies['elocookie'] = (mu,phi,sigma)
>
> logger.debug("new cookie elo %s %s %s"%(mu,phi,sigma))
> ````
>
> Could anyone tell me what I missed or misunderstood?
> Thanks, Jon.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAK8tz310vyG2NL7SSTbx3Hgbzcbd%3DW6%2BTdO0rQAYBf%2BZzxJDnA%40mail.gmail.com.

Reply via email to