Getting Beaker working with GAE
Question: I'm trying to port an app I've been running locally to GAE. The app uses the
Bottle.py framework. I use Beaker for session management. I'm a bit of a noob
and am having trouble getting Beaker imported properly. Help greatly
appreciated.

I'm running the ported app using GoogleAppEngineLauncher.app under Mac OS X
10.6.7. This runs the app in the simulation environment on my machine, not on
Google's servers.

For my GAE port, I've put Bottle.py into a directory called 'framework'. This
directory has an empty `__init__.py` file. Bottle is working fine and can
serve 'hello world'.

Beaker exists in its own directory in the root of my app (journal/beaker).
Beaker also has an empty `__init__.py`.

Relevant code:

    
    
    from framework import bottle
    from beaker import SessionMiddleware
    from google.appengine.ext import webapp
    from google.appengine.ext.webapp.util import run_wsgi_app
    
    @bottle.route('/')
    def index():
        return "hello, world"
    
    def main():
        bottle.debug(True)
        run_wsgi_app(bottle.default_app())
    
    if __name__ == '__main__':
        main()
    

I get an error message like this:

    
    
    File "/Users/mscantland/code/journal/main.py", line 19, in <module>
        from beaker import SessionMiddleware
    ImportError: cannot import name SessionMiddleware
    

Here is what I have tried to get this working so far:

  * Checked permissions on everything in /beaker to make sure they were executable.

  * Ran beaker as-is and also re-wrote all import statements so that:

from beaker.x import y

became:

    
    
    from x import y
    

  * Added 'pkg_resources.py' which is not in the standard library for the Python version GAE uses.


Answer: SessionMiddleware is in middleware.py. Try:

    
    
    from beaker.middleware import SessionMiddleware
    

