[mod_python] Re: Module importing with mod_vampire

apocalypznow apocalypznow at gmail.com
Wed Jul 12 14:54:37 EDT 2006

Thanks Graham.... I appreciate the clarity in your response.  I made the 
necessary changes, and here is what I get as a result:

Mod_python error: "PythonHandler vampire"

Traceback (most recent call last):

   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 
299, in HandlerDispatch
     result = object(req)

   File "/usr/lib/python2.3/site-packages/vampire/lookup.py", line 709, 
in _handler
     module = _import(req,file)

   File "/usr/lib/python2.3/site-packages/vampire/lookup.py", line 54, 
in _import
     module = _moduleCache.importModule(name,directory,req)

   File "/usr/lib/python2.3/site-packages/vampire/cache.py", line 316, 
in importModule

   File "/var/www/mod_python/forums/forum.py", line 8, in ?
     ticket = vampire.importModule("ticket", 

   File "/usr/lib/python2.3/site-packages/vampire/cache.py", line 161, 
in importModule
     path = os.path.normpath(path)

   File "/usr/lib/python2.3/posixpath.py", line 370, in normpath
     initial_slashes = path.startswith('/')

AttributeError: 'list' object has no attribute 'startswith'

Graham Dumpleton wrote:
> On 12/07/2006, at 9:23 PM, Graham Dumpleton wrote:
>>>> Module importing with mod_vampire is not working.  I get one of  
>>>> several old copies of the python program I am importing!
>>>> Here is the relevant section of my httpd.conf file:
>>>> Alias /forums "/var/www/mod_python/forums"
>>>> <Directory /var/www/mod_python/forums>
>>>>   SetHandler python-program
>>>>   PythonHandler vampire
>>>>   PythonDebug On
>>>>   Options -MultiViews -Indexes
>>>>   PythonPath "['/var/www/mod_python/lib','/var/www/mod_python/ 
>>>> forums']+sys.path"
> When using Vampire, you shouldn't be listing handler directories in  
> sys.path
> and if you want to use Vampire "import" hook or vampire.importModule()
> then directories targeted by them should also not be in sys.path. Thus,
> would nearly always when using Vampire use:
>   PythonPath 'sys.path'
> This ensures that no extra directories are added to sys.path.
>>>>   PythonOption VampireImportHooks On
>>>> </Directory>
>>>> The python program in question "ticket.py" is in the /var/www/ 
>>>> mod_python/lib folder.  I have also moved it to the /var/www/ 
>>>> mod_python/forums folder.  The results are the same no matter  where 
>>>> it is.  The calling program is in the /var/www/mod_python/ forums 
>>>> folder, and it does this:
>>>> import ticket
>>>> d = ticket.getData()
> Where in the calling program is this located? For the Vampire "import"
> hook to work, the "import" must be at global scope and executed on  module
> import and must not be contained within a function which is only getting
> executed when a specific request arrives.
> If this is not done, then standard Python "import" mechanism would be
> getting used and thus you would see behaviour as I explained in first
> mail for when it is used.
> Graham

More information about the Mod_python mailing list