0

while using beaker session, i came across to use same session object along the whole application.

I came through this url: Bottle.py session with Beaker

But, still i am getting 'KeyError' when i am trying to access the save session value in one function by another function.

my rest.py file looks like:

import bottle 
from bottle import route,default_app
from beaker.middleware import SessionMiddleware

app = bottle.default_app()
@bottle.hook('before_request')
def setup_request():
    request.session = request.environ['beaker.session']

@app.route('/login')
def login():
    request.session['uname'] = 'user'


@app.route('/logout')
def logout():
    print request.session['uname']
    # expecting to print user



session_opts = {
    'session.type': 'file',
    'session.data_dir': '/tmp/',
    'session.cookie_expires': True,
}
app = SessionMiddleware(bottle.default_app(),session_opts)

I have mentioned the SessionMiddleware at the end as im getting errors with the help of this link https://groups.google.com/forum/#!topic/bottlepy/m0akSbWRpZg

But when i am accessing request.session in the logout function i am getting

'KeyError': Uname not found 

can any one give clear example of how to adjust the code inorder to maintain same session in whole application.

Community
  • 1
  • 1
Gopi Krishna
  • 108
  • 2
  • 16
  • Your code uses `uname` (lower case) but your error message shows `Uname` (upper case). Typo? – ron rothman Sep 19 '16 at 23:42
  • sorry for that...actually the error comes with small 'uname', it's not about only 'uname' what ever value i used to declare ...when i access the same the getting the KeyError where that value is not there. @ron.rothman – Gopi Krishna Sep 20 '16 at 08:54

0 Answers0