[mod_python] Session ID not retained

Arnar Birgisson arnarb at oddi.is
Wed Oct 19 15:03:30 EDT 2005


Hi folks,

I've found the reason for this myself, just wanted to post it to the list if someone hits the same error in the future.

Upgrading MySQL for some reason shortened varchar(32) columns (used for the sid) to varchar(21). Apparently, this is normal when upgrading from 3.x to 4.1 since the upgrade procedure changes the internal encoding of tables from latin1 to UTF-8. However, I'm not sure what version I was running of MySQL prior to my kernel upgrade, but it was definately 4.x. After the upgrade I have 4.1.14.

Obviously, since SIDs are 32 characters long (as are other hex-coded md5 sums) no rows were being returned.

Sorry if anyone wasted their time over this.

Arnar

>>> "Arnar Birgisson" <arnarb at oddi.is> 18.10.2005 12:03 >>>
Hello there,

I was running mod_python 3.1.3 on Apache 2.0.50 with linux kernel 2.4.31 until yesterday, and all was well. For other reasons, I needed to upgrade to kernel version 2.6.13 yesterday, and along with it I upgraded my distribution from Slackware 10.0 to Slackware-current. That entailed an upgrade from libc 2.3.2 to 2.3.5.

After the upgrade, I recompiled Apache (still version 2.0.50) and compiled and installed mod_python 3.1.4. The problem now is that every request gets a new session id, even if the browser is clearly sending the pysid cookie correctly.

I was and am running python 2.4.1 both before the upgrade and now. I tried uninstalling mod_python completely, and recompiling mod_python 3.1.3 again against the new libc, but that doesn't solve the problem.

I am using að session class that I wrote myself (complete source below) that uses mysql as the data store, and the session info makes it way into the table, which tells me that sess.save() is working properly. The problem seems to be that the constructor (which just calls mod_python.Session.__init__) doesn't find the session id in the request object. I dumped request.headers_in and the pysid cookie is there.

Any ideas on what I should try next?

Arnar



My session class (which worked fine before):

from mod_python import apache, Session as apsess
from Database import getExclusiveDB
from cPickle import loads, dumps
import time

def sqlsession_cleanup():
   db = getExclusiveDB()
   c = db.cursor()
   c.execute("delete from sessiondata where (unix_timestamp() - accessed) > timeout")
   c.close()
   db.commit()
   db.close()

class SqlSession(apsess.BaseSession):

   def __init__(self, req, sid=0, secret=None, timeout=0, lock=1):
      apsess.BaseSession.__init__(self, req, sid=sid, secret=secret, timeout=timeout, lock=lock)

   def do_cleanup(self):
      self._req.register_cleanup(mem_cleanup)
      self._req.log_error("SqlSession: registered session cleanup",
            apache.APLOG_NOTICE)

   def do_load(self):
      db = getExclusiveDB()
      c = db.cursor()
      c.execute("select created, accessed, timeout, data from sessiondata where sid = %s", self._sid)
      if c.rowcount > 0:
         row = c.fetchone()
         retval = {
            "_data": loads(row[3]),
            "_created": row[0],
            "_accessed": row[1],
            "_timeout": row[2]
         }
      else:
         retval = None
      c.close()
      db.close()
      return retval

   def do_save(self, dict):
      db = getExclusiveDB()
      c = db.cursor()
      c.execute("replace into sessiondata (sid, created, accessed, timeout, data) "
            + "values (%s, %s, %s, %s, %s)", 
            (self._sid, dict['_created'], dict['_accessed'], dict['_timeout'], dumps(dict['_data'])))
      c.close()
      db.commit()
      db.close()

   def do_delete(self):
      db = getExclusiveDB()
      c = db.cursor()
      c.execute("delete from sessiondata where sid = %s", self._sid)
      c.close()
      db.commit()
      db.close()



_______________________________________________
Mod_python mailing list
Mod_python at modpython.org 
http://mailman.modpython.org/mailman/listinfo/mod_python




More information about the Mod_python mailing list