sessions with wsgi on 0.3

219 views
Skip to first unread message

foobarmus

unread,
Jul 18, 2008, 12:10:58 PM7/18/08
to web.py
Sorry, I couldn't find anything on this at a level I could
understand... Is there some trick to getting session.py working with
wsgi? My error, from a modified version of the session example in the
cookbook, is:

AttributeError: 'function' object has no attribute 'add_processor'

I'm hitting the same error with my main app as well, so I think I must
be getting close to having it all working.

foobarmus

unread,
Jul 21, 2008, 3:47:49 AM7/21/08
to web.py
Got it working

Maybe this should have been obvious, but to me it wasn't...

application = web.application(urls, globals()).wsgifunc()
app = web.application(urls, locals())
session = web.session.Session(app,
web.session.DiskStore('/home/foob/wsgi_test/sessions'),
initializer={'count': 0})

foobarmus

unread,
Jul 24, 2008, 1:54:40 AM7/24/08
to web.py
Actually it wasn't working at that point (doh!) but it is now,
finally. Session and application must use the same app instance, like
this

app = web.application(urls, globals())
application = app.wsgifunc()
session = web.session.Session(app,
web.session.DiskStore('/home/foob/wsgi_test/sessions'),
initializer={'count': 0})

rostoQ

unread,
Jul 24, 2008, 8:01:05 AM7/24/08
to web.py
are you able to use DBStore instead of DiskStore? When using the
example, it returns

"File "./code.py", line 9, in <module>
store = DBStore(db, 'sessions')
NameError: name 'DBStore' is not defined"


code:
#!/usr/bin/env python
import web
urls = (
"/count", "count",
"/reset", "reset"
)
app = web.application(urls, locals())
db = web.database(dbn='postgres', db='tagsite', user='jan',
pw='iluvatar')
store = DBStore(db, 'sessions')
session = web.session.Session(app, store, initializer={'count': 0})

class count:
def GET(self):
session.count += 1
return str(session.count)

class reset:
def GET(self):
session.kill()
return ""

if __name__ == "__main__":
app.run()

Anand Chitipothu

unread,
Jul 24, 2008, 9:33:22 AM7/24/08
to we...@googlegroups.com
On Thu, Jul 24, 2008 at 5:31 PM, rostoQ
<koreanisches....@yahoo.de> wrote:
>
> are you able to use DBStore instead of DiskStore? When using the
> example, it returns
>
> "File "./code.py", line 9, in <module>
> store = DBStore(db, 'sessions')
> NameError: name 'DBStore' is not defined"

from web.session import DBStore

corrected cookbook example.
http://webpy.org/cookbook/sessions

Reply all
Reply to author
Forward
0 new messages