Graham Dumpleton
graham.dumpleton at gmail.com
Mon Feb 4 17:27:20 EST 2008
What settings do you have in your configuration for: PythonPath ... PythonOption mod_python.importer.path ... The module importer doesn't add paths automatically to sys.path and uses its own path which is in part based on the request context. The locations it can look in can therefore vary based on where your handler code is located which the request mapped to. As such, you may need to explicitly set the module importer path option if a specific directory must always be checked. The other option is that if you are relying on being able to import from a module installed on sys.path, ie., standard module, a module which only exists somewhere on mod_python module path. You can't do this, when using 'import' in a standard Python module, it will only look for stuff on sys.path. Answer these questions, but also make sure you have read up on import_module function in: http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html if you haven't done so already. Graham On 05/02/2008, Tom Wells <drshade at gmail.com> wrote: > Hi Everyone > > I have been bumbling along with mod_python for about a month using > mod_python as the apache hooks for integrating into a larger single-sign-on > solution, so far so good. However I'm hitting my head against a weird issue, > and can't seem to find any reference to related issues on this list, nor the > FAQ, so here goes: > > I'm supporting multiple apache virtual hosts, and separating them by running > each in a different python interpretor (using PythonInterpreter <site_name> > within the VirtualHost configuration for each site. > > I hook into apache via PythonAuthenHandler and PythonAuthzHandler (as my app > is only concerned with authentication and authorization) and make web > service calls using ZSI and some cryptographic routines using ncrypt (Python > OpenSSL wrapper) before allowing or disallowing access to the particular > resource. > > So the above works nicely, but while testing I occasionally get the > following error (not on startup, but after a few requests): > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module '/home/tom/dev/auth/ssofilter-apache-2.2/ssofilter.py' > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module '/home/tom/dev/auth/ssofilter-apache-2.2/webserver.py' > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module '/home/tom/dev/auth/ssofilter-apache-2.2/cache.py' > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module '/home/tom/dev/auth/ssofilter-apache-2.2/authserver.py' > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module '/home/tom/dev/auth/ssofilter-apache-2.2/ausService_services.py' > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module > '/home/tom/dev/auth/ssofilter-apache-2.2/ausService_services_types.py' > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module '/home/tom/dev/auth/ssofilter-apache-2.2/utils.py' > [Mon Feb 04 17:41:57 2008] [notice] mod_python (pid=26429, > interpreter='ssofilter_interpreter_mobile'): Importing > module '/home/tom/dev/auth/ssofilter-apache-2.2/cryptography.py' > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] mod_python > (pid=26429, interpreter='ssofilter_interpreter_mobile', > phase='PythonAuthenHandler', handler='ssofilter'): Application error > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] ServerName: > 'mobile.domain.co.za' > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] DocumentRoot: > '/home/tom/dev/auth/mobileweb' > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] URI: '/' > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Location: '/' > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Directory: None > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Filename: > '/home/tom/dev/auth/mobileweb/' > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] PathInfo: '' > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] Traceback (most > recent call last): > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/usr/lib/python2.5/site-packages/mod_python/importer.py", > line 1537, in HandlerDispatch\n default=default_handler, arg=req, > ilent=hlist.silent) > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/usr/lib/python2.5/site-packages/mod_python/importer.py", > line 1202, in _process_target\n module = import_module(module_name, > path=path) > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/usr/lib/python2.5/site-packages/mod_python/importer.py", > line 296, in import_module\n log, import_path) > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/usr/lib/python2.5/site-packages/mod_python/importer.py", > line 680, in import_module\n execfile(file, module.__dict__) > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/home/tom/dev/auth/ssofilter-apache-2.2/ssofilter.py", line 10, in > <module>\n cryptography = apache.import_module('cryptography') > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/usr/lib/python2.5/site-packages/mod_python/importer.py", > line 296, in import_module\n log, import_path) > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/usr/lib/python2.5/site-packages/mod_python/importer.py", > line 680, in import_module\n execfile(file, module.__dict__) > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/home/tom/dev/auth/ssofilter-apache-2.2/cryptography.py", line 4, in > <module>\n cipher = apache.import_module('ncrypt.cipher') > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/usr/lib/python2.5/site-packages/mod_python/importer.py", > line 304, in import_module\n return __import__(module_name, {}, {}, > ['*']) > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] File > "/var/lib/python-support/python2.5/ncrypt/cipher.py", line > 1, in <module>\n from _ncrypt.cipher import * > [Mon Feb 04 17:41:57 2008] [error] [client 192.168.16.42] ImportError: No > module named cipher > > Now you may think I'm posting this to the wrong list looking at the > stacktrace, but I'm convinced it's mod_python related. While testing the > first few requests go through fine (and ncrypt is imported correctly), but > it seems like the error occurs when apache has decided to create a new > thread (or spawn a new process, difficult to tell) that the error occurs > (the log entries containing "Importing Module" are spat out by mod_python, > as I use the apache.import_module() function for performing all my imports). > > A hint is if I make all my sites run under one single python interpreter (by > giving them the same name) I don't experience the problem, but I'd prefer > not to run under this configuration as I'd need to do a whole lot more work > to ensure that data remains separated per site. > > Any comments, suggestions would be greatly appreciated! > > Thanks, > Tom > > PS> Running mod_python 3.3.1-2, running on ubuntu 7.10 in apache > 2.2.4-3build1. My apache runtime configuration looks something like: > [Mon Feb 04 17:40:10 2008] [notice] Apache Configuration: > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MAX_DAEMON_USED -> 2 [Max # > of daemons used so far] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_IS_THREADED -> 1 > [0=Unsupported, 1=Static, 2=Dynamic] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_IS_FORKED -> 2 > [0=Unsupported, 1=Static, 2=Dynamic] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_HARD_LIMIT_DAEMONS -> 16 [The > compiled max # daemons] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_HARD_LIMIT_THREADS -> 64 [The > compiled max # threads] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MAX_THREADS -> 25 [# > of threads/child by config] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MIN_SPARE_DAEMONS -> 0 [Min # > of spare daemons] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MIN_SPARE_THREADS -> 25 [Min > # of spare threads] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MAX_SPARE_DAEMONS -> 0 [Max > # of spare daemons] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MAX_SPARE_THREADS -> 75 [Max > # of spare threads] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MAX_REQUESTS_DAEMON -> 10 [Max > # of requests per daemon] > [Mon Feb 04 17:40:10 2008] [notice] AP_MPMQ_MAX_DAEMONS -> 6 [Max > # of daemons by config] > > > > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python > >
|