[mod_python] Session ID not retained

Arnar Birgisson arnarb at oddi.is
Tue Oct 18 08:03:19 EDT 2005


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()





More information about the Mod_python mailing list