Graham Dumpleton
graham.dumpleton at gmail.com
Tue Mar 13 16:22:38 EST 2007
On 13/03/07, me <mlists at e-beyond.de> wrote: > Hi there, > > I've got an issue with mod_python. There is a script (index.py) wich is > processed when I go to http://www.xyz.somewhere/ but when I reload > the page 3-4 times I'll receive the error below. It doesn't matter if the page > is reloaded fast or slowly. > The only point that may be an problem (but I didn't think so) is a factory > which should provide the classes for the modules (not the python-modules) of > the site. > > thanks for your help!! > marc > > mod_python: 3.3.1 > python 2.4 > > The Factory: > class ContentFactory: > def factory(self,className, *args): > aClass = getattr(__import__(__name__), className) Why are you using __name__ as argument to __import__ here as that would mean you are trying to import the same module as the code is in, although that will not actually work as you think as modules like your index.py file are imported by special mod_python module importer and __name__ will not be 'index' but in this case '_mp_977643700f732f7a07a576608a2136c2'. Since the mod_python module importer will not find a .py file by that name, it will fallback to Python importer which I would have though would have failed to find it. Are you really wanting to import the same module as the code is in? Rather than using __import__() you might be better off looking at the apache.import_module() function as described in: http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html This will give you better control over module importing as file can be specified by full path. Also allows automatic module reloading. Graham > return apply(aClass, args) > > The error-message: > MOD_PYTHON ERROR > > ProcessId: 29986 > Interpreter: 'www.xyz.somehwere' > > ServerName: 'www.xyz.somehwere' > DocumentRoot: '/www/www.xyz.somehwere/htdocs' > > URI: '/' > Location: '/' > Directory: None > Filename: '/www/www.xyz.somehwere/htdocs/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 1537, > in HandlerDispatch > default=default_handler, arg=req, silent=hlist.silent) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1229, > in _process_target > result = _execute_target(config, req, object, arg) > > File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1128, > in _execute_target > result = object(arg) > > File "/usr/lib/python2.4/site-packages/mod_python/publisher.py", line 213, > in handler > published = publish_object(req, object) > > File "/usr/lib/python2.4/site-packages/mod_python/publisher.py", line 425, > in publish_object > return publish_object(req,util.apply_fs_data(object, req.form, req=req)) > > File "/usr/lib/python2.4/site-packages/mod_python/util.py", line 554, in > apply_fs_data > return object(**args) > > File "/www/www.xyz.somehwere/htdocs/index.py", line 6, in index > return c.getResponse() > > File "/www/www.xyz.somehwere/htdocs/_module/Content.py", line 28, in > getResponse > return Template ( file = self.req.document_root() > + '/_templates/standard.tmpl', searchList = [{ 'authenticated': > self.authenticated , 'content' : self._processContent()}] ) > > File "/www/www.xyz.somehwere/htdocs/_module/Content.py", line 23, in > _processContent > contentRunner = cp.factory('MainIndex',self.req) > > File "/www/www.xyz.somehwere/htdocs/_module/ContentFactory.py", line 6, in > factory > aClass = getattr(__import__(__name__), className) > > AttributeError: 'module' object has no attribute 'MainIndex' > > > MODULE CACHE DETAILS > > Accessed: Tue Mar 13 13:08:47 2007 > Generation: 1 > > _mp_977643700f732f7a07a576608a2136c2 { > FileName: '/www/www.xyz.somehwere/htdocs/index.py' > Instance: 1 > Generation: 1 > Modified: Tue Mar 13 09:10:38 2007 > Imported: Tue Mar 13 12:41:52 2007 > } > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python > > >
|