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 no cookies or
cookies -- 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---