Gavin
gavin at sz.net.cn
Tue Feb 21 07:09:54 EST 2006
> > On 21/02/2006, at 10:14 PM, Gavin wrote: >>> All I can suggest then is to modify lib/python/mod_python/ >>> Session.py in >>> mod_python source code and add in some debug statements to see what >>> session database name is being set to. >>> >>> class DbmSession(BaseSession): >>> >>> def __init__(self, req, dbm=None, sid=0, secret=None, >>> dbmtype=anydbm, >>> timeout=0, lock=1): >>> >>> if not dbm: >>> opts = req.get_options() >>> if opts.has_key("session_dbm"): >>> dbm = opts["session_dbm"] >>> else: >>> dbm = os.path.join(opts.get('session_directory', >>> tempdir), 'mp_sess.dbm') >>> >>> self._dbmfile = dbm >>> self._dbmtype = dbmtype >>> >>> # XXX DEBUG >>> >>> apache.log_error("dbmfile=%s"%self._dbmfile) >>> >>> Reinstall mod_python and restart Apache. >>> >>> Then when running test, look in Apache error_log to see where it >>> thinks it is getting >>> put. See if file exists if not in /tmp. >>> >> mp_sess_test.dbm file doesn't exists in /tmp. error_log file are as >> following: > > Run an interactive Python session and try: > > grumpy:~ grahamd$ python > Python 2.3.5 (#1, Mar 20 2005, 20:38:20) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import anydbm > >>> db = anydbm.open("/tmp/mp_sess_test.dbm",'c') > >>> Yes, it works correctly. > > If that works, try the same thing in a really simple mod_python handler > independent of Session class. Ie., > > from mod_python import apache > import anydbm > > def handler(req): > req.content_type = 'text/plain' > db = anydbm.open("/tmp/mp_sess_test.dbm",'c') > db.close() > req.write('test ok') > return apache.OK > > If it works outside of mod_python and not in mod_python, may be some > problem to do with a mixing of wrong versions of shared libraries. > > If it doesn't work outside of mod_python either, make sure permissions > on "/tmp" directory look correct, or try creating it in a different > directory > that you own. right. It doesn't work . I create a test directory, and test as following: <Directory "/data/HTTPD/htdocs/t"> AddHandler mod_python .m .cgi .py #PythonHandler mod_python.psp PythonHandler myhandler PythonOption session_dbm /opt/tmp/mp_sess.dbm PythonPath "['/data/HTTPD/py_api']+['/data/HTTPD/htdocs/t']+sys.path" PythonDebug On Options Indexes FollowSymLinks Order deny,allow Allow from all </Directory> Create a myhandler.py file in t directory: from mod_python import apache import anydbm def handler(req): req.content_type = 'text/plain' db = anydbm.open("/tmp/mp_sess_test.dbm",'c') db.close() req.write('test ok') return apache.OK when accessing by http://myserver/t/myhandler.py. An error hanppen as following(the t directory 's permissions is 777.) Mod_python error: "PythonHandler myhandler" Traceback (most recent call last): File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/data/HTTPD/htdocs/t/myhandler.py", line 7, in handler db = anydbm.open("/tmp/mp_sess_test.dbm",'c') File "/usr/local/lib/python2.4/anydbm.py", line 83, in open return mod.open(file, flag, mode) File "/usr/local/lib/python2.4/dbhash.py", line 16, in open return bsddb.hashopen(file, flag, mode) File "/usr/local/lib/python2.4/bsddb/__init__.py", line 285, in hashopen e = _openDBEnv() File "/usr/local/lib/python2.4/bsddb/__init__.py", line 339, in _openDBEnv e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL) DBError: (147320808, 'Unknown error 147320808') > > Time for me to sleep. Will see how you go in the morning. > > Graham >
|