Question

I'm kind of lost here. How can I get started with a python script using pyramid beaker. I prefer to invoke it through uwsgi like this:

uwsgi -s :9001  --module script

but when I call it using curl I get

KeyError: 'beaker.session'

script.py is like this

from beaker.middleware import SessionMiddleware
from pyramid.config import Configurator

def application(environ, start_response):
    # Get the session object from the environ
    session = environ['beaker.session']

    start_response('200 OK', [('Content-type', 'text/plain')])
    return ['returned']

# Configure the SessionMiddleware
session_opts = {
    'session.type': 'file',
    'session.cookie_expires': True,
}
#wsgi_app = SessionMiddleware(application, session_opts)
config = Configurator()
config.include('pyramid_beaker')
wsgi_app = SessionMiddleware(application, session_opts)

Thanks!

Was it helpful?

Solution

uwsgi -s :9001 --module script:wsgi_app

is what you need, otherwise uWSGI will call the "application" function, skipping the middleware

OTHER TIPS

You should not be using the SessionMiddleware in conjunction with pyramid_beaker. Pyramid provides it's own interface to the session object via request.session automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top