Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How am I supposed to use this module? #4

Open
yoooooooooooooooooooooooo opened this issue Jul 9, 2018 · 4 comments
Open

How am I supposed to use this module? #4

yoooooooooooooooooooooooo opened this issue Jul 9, 2018 · 4 comments

Comments

@yoooooooooooooooooooooooo
Copy link

yoooooooooooooooooooooooo commented Jul 9, 2018

The example doesn't work:

    import bottle
    from bottle.ext import beaker
    
    session_opts = {
        'session.type': 'file',
        'session.cookie_expires': 300,
        'session.data_dir': './data',
        'session.auto': True
    }
    
    app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts)
    
    @bottle.route('/test')
    def test():
        s = bottle.request.environ.get('beaker.session')
        s['test'] = s.get('test',0) + 1
        s.save()
        return 'Test counter: %d' % s['test']
    
    bottle.run(app=app)

s is always None and I don't understand why...

@yoooooooooooooooooooooooo
Copy link
Author

    Exception:
    AttributeError("'NoneType' object has no attribute 'get'",)

@signalw
Copy link

signalw commented Jul 29, 2018

That's weird. I tried your exact same code and didn't run into any problems. Worked on both python2.7 and python3.6

@dorel14
Copy link

dorel14 commented Aug 5, 2019

Hello, same for me
AttributeError: 'NoneType' object has no attribute 'get'
Linux centos + python 3.6

@defnull
Copy link
Member

defnull commented Aug 5, 2019

If s is None, then beaker middleware did not inject the session object. The example code actually does not use this plugin, but directly applies the beaker session middleware to the whole bottle application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants