Search code examples
pythongoogle-app-enginewsgibottlebeaker

Enabling Beaker SessionMiddleware through Bottle on Google App Engine


I am trying to use beaker for session handling in my bottle based GAE app. The problem is that I need to run "app" here as the app

session_opts = {
    'session.type': 'ext:google',
    'session.auto': True,
}

app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts)

then call

bottle.run(app=app)

but I can't because as it says in the example bottle app:

# Note: We don't need to call run() since our application is embedded within
# the App Engine WSGI application server.

So my question is how can I run the server with the beaker session middleware?


Solution

  • Okay I have found the cause of the problem - thanks for getting me to think Gianni. Basically I had

    - url: .*
      script: main.bottle
    

    which means that GAE treats the bottle variable in my main.py as the "app". So when I did this instead:

    from bottle import app, route, hook...
    
    session_opts = {
        'session.type': 'ext:google',
        'session.auto': True,
    }
    
    bottle = beaker.middleware.SessionMiddleware(app(), session_opts)
    

    It all worked a treat. Guess that'll teach me for not reading the app engine docs enough.