views:

39

answers:

2

Hi,

I'm programming an application with google app engine, with django 1.1 (no django pacth or others), well as you know is impossible use django login and session features so I download Gae utility and use Session Object (http://gaeutilities.appspot.com/) but some time this object create 2 sessions instead 1 session ... here's code

def index(request):

     aSWrap = SWrap(SWrap.createSession())
     ....
      def login(request):

     aSWrap = SWrap(SWrap.createSession())
     ....


      class SWrap(object):

   @classmethod    
   def createSession():

     return Session(cookie_name='my_cookie',session_expire_time=7200)

and for setting session no expiration or really long expiration...enter code here Thanks

+2  A: 

I suggest using a different sessions library. Check out this comparison of the available sessions libraries for GAE.

I'd recommend gae-sessions - it presents an API almost identical to the library you are currently using, but it is much faster and shouldn't give you headaches like the bug you've encountered above.

Disclaimer: I wrote gae-sessions, but I'm not the only one who would recommend it. Here is a recent thread discussing sessions on the google group for GAE python.

David Underhill
wow thanks I will try it soon, and thanks to share your library
and is it strong like gaeutilities? I mean about security issue
Yes, they are both equally resistant to session hijacking and fixation attacks (and the same with other session libraries). Of course all of them all vulnerable to man-in-the-middle attacks unless your users are connected over a secure channel (HTTPS). So use HTTPS (or switch to HTTPS and change the session ID) for portions of your site where security is paramount (just like Amazon and others do).
David Underhill
ok, great I'm already switching to your session lib it's great thanks
You're welcome, enjoy!
David Underhill
A: 

What are you trying to do with SWrap(SWrap.createSession())? It looks like the result of SWrap.createSession() is passed to the SWrap() constructor. Have you omitted part of the definition of SWrap?

Perhaps this is more what you are wanting:

def index(request):
    mysession = SWrap.createSession()
    ....

def login(request):
    mysession = SWrap.createSession()
    ....

class SWrap(object):
    @staticmethod    
    def createSession():
        return Session(cookie_name='my_cookie',session_expire_time=7200)
cope360
yes I've omitted, before I've tried to put create session into constructor but don't works at all :) thanks for the answer

related questions