Session Examples not working #132

Open
theredpea opened this Issue Jan 23, 2012 · 6 comments

Projects

None yet

3 participants

I get this error:
<type 'exceptions.AttributeError'> at /
'ThreadedDict' object has no attribute 'count'
Python C:\Python27\Lib\site-packages\web\session.py in getattr, line 70
Web GET http://localhost:1234/

When I run this code:
http://webpy.org/cookbook/session_with_reloader

Except that I added this at the top:

web.config.debug=True

So I could see the error results seen at top.

When I run the normal Sessions example
http://webpy.org/cookbook/sessions

I get an internal server error.

Could someone explain a workaround?

marians commented Jan 24, 2012

Having the same problem...

marians commented Jan 24, 2012

Just found this hint

"sessions doesn't work in debug mode because it interfere with reloading."

on that page: http://webpy.org/cookbook/sessions

marians commented Jan 24, 2012

It seems like the session documentation isn't up to date at all. The database schema in the example code isn't correct and the config parameters in the examples aren't either.

I got it working with 0.36 now. Here is my MySQL table definition:

CREATE TABLE webapp_sessiondata (
session_id char(128) NOT NULL,
atime timestamp NOT NULL default CURRENT_TIMESTAMP,
data text,
UNIQUE KEY session_id (session_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

In my web.config.session_parameters I had to correct several things:

  • secret_key has to exist, and the lengths is obviously required to be 20 characters.
  • httponly has to be set (boolean)
  • secure has to be set (boolean).

The source https://github.com/webpy/webpy/blob/master/web/session.py pointed me to that.

To initialize the DBStore, I am doing this now:

db = web.database(dbn='mysql', db='mydb', user='myuser', pw='')
app = web.application(urls, globals())
store = web.session.DBStore(db, 'webapp_sessiondata')
session = web.session.Session(app, store, initializer={'count': 0})

Good luck!

Update: I have to say that it doesn't work completely yet. I get no errors, but web.py generates a new session ID with every request, not even looking up the existing one in the database. At least my session data isn't updated, instead the table is being filled up with new entries.

Update 2: Found the problem. It's described in Issue#89 #89 and with the patch applied and cookie_path set to "/" it works well.

Thanks Marian!

But I could not get DiskStore to work, versus the Database;
Have you gotten DiskStore to work?

http://webpy.org/cookbook/sessions

I'm new to Databases, so I'm intimidated to try your fixes...

Nathaniel Muir Anderson
P: (213)814-8942
E: nate.muir.anderson@gmail.com
A: 1045 W Radcliff Ave | Englewood, CO | 80110

On Tue, Jan 24, 2012 at 3:14 AM, Marian Steinbach <
reply@reply.github.com

wrote:

It seems like the session documentation isn't up to date at all. The
database schema in the example code isn't correct and the config parameters
in the examples aren't either.

I got it working with 0.36 now. Here is my MySQL table definition:

CREATE TABLE webapp_sessiondata (
session_id char(128) NOT NULL,
atime timestamp NOT NULL default CURRENT_TIMESTAMP,
data text,
UNIQUE KEY session_id (session_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

In my web.config.session_parameters I had to correct several things:

  • secret_key has to exist, and the lengths is obviously required to be 20
    characters.
  • httponly has to be set (boolean)
  • secure has to be set (boolean).

The source https://github.com/webpy/webpy/blob/master/web/session.pypointed me to that.

To initialize the DBStore, I am doing this now:

db = web.database(dbn='mysql', db='mydb', user='myuser', pw='')
app = web.application(urls, globals())
store = web.session.DBStore(db, 'webapp_sessiondata')
session = web.session.Session(app, store, initializer={'count': 0})

Good luck!


Reply to this email directly or view it on GitHub:
#132 (comment)

marians commented Jan 24, 2012

Sorry, haven't tried the DiskStore.

El-Adrel commented May 2, 2014

any progress fellas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment