Graham Dumpleton
grahamd at dscpl.com.au
Fri Dec 1 16:41:05 EST 2006
On 02/12/2006, at 12:03 AM, Clodoaldo wrote: > I'm trying to import a module with both the third and fourth > techniques you described but I'm having errors. > > This is the Virtual host config: > > ServerName carconsumption.s0 > DocumentRoot /var/www/html/carconsumption.com > SetHandler mod_python > PythonHandler mod_python.publisher > PythonDebug On > PythonOption mod_python.importer.path "['~/mod']" > PythonImport db_connection carconsumption.s0 > > The module "constants" is in the mod directory under the document > root: > > [cpn at s0 mod]$ pwd > /var/www/html/carconsumption.com/mod > [cpn at s0 mod]$ ll constants.py > -rwxr----- 1 cpn apache 28675 Nov 29 17:42 constants.py > [cpn at s0 mod]$ ll -d ../mod > drwxrws--- 2 cpn apache 4096 Dec 1 12:26 ../mod > > Third technique. index.py contains: > > from mod_python import apache > C = apache.import_module('~/mod/constants.py') > > The error output: > > MOD_PYTHON ERROR > > ProcessId: 24982 > Interpreter: 'carconsumption.s0' > > URI: '/' > Location: None > Directory: None The '~/' prefix will be replaced with the value of 'Directory' as shown here, but it isn't set because you have the PythonHandler directive outside of any Directory directive or .htaccess file. Thus, it can't know what the handler root is. Using: DocumentRoot /var/www/html/carconsumption.com <Directory /var/www/html/carconsumption.com> SetHandler mod_python PythonHandler mod_python.publisher PythonDebug On PythonOption mod_python.importer.path "['~/mod']" </Directory> should work, as will: DocumentRoot /var/www/html/carconsumption.com SetHandler mod_python PythonHandler mod_python.publisher PythonDebug On PythonOption mod_python.importer.path "['/var/www/html/ carconsumption.com/mod']" Note, when inside a Location directive, '~/' will not work either as Location isn't associated with a directory. What I have to think about now is whether when both Directory and Location directives aren't being used, that '~/' maps to DocumentRoot. I never thought about this particular scenario. Graham > Filename: '/var/www/html/carconsumption.com/index.py' > PathInfo: '' > > Phase: 'PythonHandler' > Handler: 'mod_python.publisher' > > Traceback (most recent call last): > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1522, in HandlerDispatch > default=default_handler, arg=req, silent=hlist.silent) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1227, in _process_target > result = _execute_target(config, req, object, arg) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1126, in _execute_target > result = object(arg) > > File "/usr/lib/python2.4/site-packages/mod_python/publisher.py", > line 204, in handler > module = page_cache[req] > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1057, in __getitem__ > return import_module(req.filename) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 294, in import_module > log, import_path) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 678, in import_module > execfile(file, module.__dict__) > > File "/var/www/html/carconsumption.com/index.py", line 4, in ? > C = apache.import_module('~/mod/constants.py') > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 302, in import_module > return __import__(module_name, {}, {}, ['*']) > > ImportError: No module named ~/mod/constants.py > > > MODULE CACHE DETAILS > > Accessed: Fri Dec 1 12:33:24 2006 > Generation: 0 > > _mp_96eec165c095033cec4187d8d6982912 { > FileName: '/var/www/html/carconsumption.com/index.py' > Instance: 1 [IMPORT] > Generation: 0 [ERROR] > Modified: Fri Dec 1 12:31:11 2006 > } > > When i give the absolute path it works: > from mod_python import apache > C = apache.import_module('/var/www/html/carconsumption.com/mod/ > constants.py') > > Fourth technique. index.py contains: > > import constants as C > > The error: > > MOD_PYTHON ERROR > > ProcessId: 24983 > Interpreter: 'carconsumption.s0' > > URI: '/' > Location: None > Directory: None > Filename: '/var/www/html/carconsumption.com/index.py' > PathInfo: '' > > Phase: 'PythonHandler' > Handler: 'mod_python.publisher' > > Traceback (most recent call last): > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1522, in HandlerDispatch > default=default_handler, arg=req, silent=hlist.silent) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1227, in _process_target > result = _execute_target(config, req, object, arg) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1126, in _execute_target > result = object(arg) > > File "/usr/lib/python2.4/site-packages/mod_python/publisher.py", > line 204, in handler > module = page_cache[req] > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 1057, in __getitem__ > return import_module(req.filename) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 294, in import_module > log, import_path) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line > 678, in import_module > execfile(file, module.__dict__) > > File "/var/www/html/carconsumption.com/index.py", line 3, in ? > import constants as C > > ImportError: No module named constants > > > MODULE CACHE DETAILS > > Accessed: Fri Dec 1 12:34:55 2006 > Generation: 0 > > _mp_96eec165c095033cec4187d8d6982912 { > FileName: '/var/www/html/carconsumption.com/index.py' > Instance: 1 [IMPORT] > Generation: 0 [ERROR] > Modified: Fri Dec 1 12:34:19 2006 > } > > > Regards, > -- > Clodoaldo Pinto Neto
|