[mod_python] KeyError Exception when doing sys.modules[class.__module__] (vampire?)

Keerati Inochanon unselfishly at gmail.com
Sat Apr 2 20:10:32 EST 2005


Hi,

I'm getting this exception:
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 641,
in _handler
    result = _execute(req,objects[-1])

  File "/usr/lib/python2.3/site-packages/vampire/lookup.py", line 445,
in _execute
    return object(**args)

  File "/home/www/testing/upload.py", line 56, in handler
    FileHandler.processUpload(filename, destination)

  File "/home/www/testing/modules/FileHandler.py", line 149, in processUpload
    def getFileHandler(filename, module=sys.modules[FileHandler.__module__]):

KeyError: '_vampire_c5f8def7c7c8bbf5b9d75d365a5bbe67_37'
--

I'm not sure this it is related to vampire or not, but it seems to
happen when I do module loading through vampire. I tried to run the
same code with python import, and the code was running fine.

Here is my code snippet:

FileHandler.py:
------------------------------
import os
import sys
import vampire

config = vampire.loadConfig(__req__, ".vampire")
directory = config.get("Modules", "common")
SessionManagement = vampire.importModule("SessionManagement", directory)
Settings = vampire.importModule("Settings", directory, __req__)

class FileHandler:
...
...
...

class XYZFileHandler:
...
...
...

def processUpload(filename, directory):
  "Process the user-uploaded files"

  def getFileHandler(filename, module=sys.modules[FileHandler.__module__]):
    "Return the file handler class according to the file extension"
    
    subclass = "%sFileHandler" % os.path.splitext(filename)[1].upper()[1:]
    return hasattr(module, subclass) and getattr(module, subclass) or
FileHandler
  
  getFileHandler(filename)(filename, directory)
------------------------------------------------
upload.py:
from mod_python import apache, util
from mod_python.Session import Session
import vampire
import os

config = vampire.loadConfig(__req__, ".vampire")
directory = config.get("Modules", "common")
SessionManagement = vampire.importModule("SessionManagement", directory)
Settings = vampire.importModule("Settings", directory)
FileHandler = vampire.importModule("FileHandler", directory, __req__)
Utility = vampire.importModule("Utility", directory, __req__)

def handler(req, **kwargs):
...
...
  FileHandler.processUpload(filename, destination)
...
...

---------------------------------------------------
What am I doing wrong? Please let me know if you need more
information. Thank you very much in advance.

Best regards,
Keerati Inochanon


More information about the Mod_python mailing list