I've had the same problem and also got no useful advice on my similar
post.  So you're not alone.   I'm surprised this is not a more common
problem or perhaps everyone knows the solution except us.

I tried memcache but you need a separate key for each user to avoid
that concurrency overlap, and there is no way to pass that key between
event handlers (except cookies).  So might as well just use cookies.

Thanks for posting this solution.

On Oct 6, 2:05 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> This might help others starting from the cookie-ignorant place I
> started from.
>
> Never got back any advice, so after a whole lot of Googling I ended up
> putting code like this on my index page:
>
> import sha, datetime, time, Cookie, os
>
> ....
>
>         #Set session ID cookie if one doesn't already exist.
>         cookie_string = os.environ.get('HTTP_COOKIE')
>         if cookie_string:
>             cookie = Cookie.SimpleCookie()
>             cookie.load(cookie_string)
>             if not cookie.has_key('sid'):
>                 sid = sha.new(repr(time.time())).hexdigest()
>                 expires = datetime.datetime.now() +
> datetime.timedelta(hours=2)
>                 expires = expires.strftime('%a, %d %b %Y %H:%M:%S')
>                 self.response.headers.add_header(
>                     'Set-Cookie', 'sid=%s' % sid + '; expires=%s' %
> expires)
>         else:
>             sid = sha.new(repr(time.time())).hexdigest()
>             expires = datetime.datetime.now() +
> datetime.timedelta(hours=2)
>             expires = expires.strftime('%a, %d %b %Y %H:%M:%S')
>             self.response.headers.add_header(
>                 'Set-Cookie', 'sid=%s' % sid + '; expires=%s' %
> expires)
>
> A more elegant logic is undoubtedly possible, but is seems to set a
> session id cookie in all cases (whether there are nocookiesorcookies-- i.e. 
> for Google Analytics -- but not the SID cookie)
>
> I then check for the SID on other pages with
>
>         cookie_string = os.environ.get('HTTP_COOKIE')
>         cookie = Cookie.SimpleCookie()
>         cookie.load(cookie_string)
>         sid = cookie['sid'].value
>
> I then use this SID for all saves and queries to the datastore per a
> user's (i.e., a guest, as I don't require logins) session.
>
> Seems to work, though I've just uploaded the code. Let's see how it
> holds up. No more concurrency issues though.
>
> If people have found a better solution, I'd like to hear about it.
>
> Jason
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to