Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-12

ImportError: cannot import name publisher

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1.3
    • 3.2.7
    • importer
    • None

    Description

      From mailing list.

      ImportError: cannot import name publisher
      ------------------------------------

      In a directory publisher, setup for mod_python.publisher as described in
      previous email, and with same index.py. Ie.,

      import os
      def index():
      return os.getpid(),_file_

      Now create a parallel directory called "handler" and in its .htaccess file add:

      SetHandler python-program
      PythonHandler mptest
      PythonDebug On

      The mptest.py file in that directory should read:

      from mod_python import apache
      import os

      from mod_python import publisher

      def handler(req):
      req.content_type = "text/plain"
      req.send_http_header()
      req.write(str((os.getpid(),_file_)))
      return apache.OK

      Restart Apache to clear caches and access "handler" and "publisher"
      directories in that order. One gets:

      (747, '/Users/grahamd/Sites/handler/mptest.py')
      (747, '/Users/grahamd/Sites/publisher/index.py')
      (747, '/Users/grahamd/Sites/handler/mptest.py')
      (747, '/Users/grahamd/Sites/publisher/index.py')

      Okay, everything is fine.

      Now restart Apache to clear caches and access "publisher" and then
      "handler". Ie., in reverse order. One gets:

      (761, '/Users/grahamd/Sites/publisher/index.py')

      Mod_python error: "PythonHandler mptest"

      Traceback (most recent call last):

      File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 296, in HandlerDispatch
      log=debug)

      File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 421, in import_module
      autoreload=autoreload,log=log,path=path)

      File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 474, in _unsafe_import_module
      module = imp.load_module(mname, f, p, d)

      File "/Users/grahamd/Sites/handler/mptest.py", line 4, in ?
      from mod_python import publisher

      ImportError: cannot import name publisher

      The way in which mod_python.publisher is loaded as PythonHandler,
      if done before being imported explicitly using "import", screws up
      that latter import.

      I know some will scream that I am mixing "import" and "import_module()",
      but since mod_python.publisher is installed into "site-packages", one
      should expect it to work with "import". Whether it does is order dependent.

      Because I use mod_python.publisher in Vampire for its user authentication
      stuff, this problem means that if using Vampire and elsewhere also wanting
      to use mod_python.publisher as PythonHandler, that the Vampire area
      should be setup with its own PythonInterpreter instance.

      Having now remembered this problem, as a workaround in Vampire I
      should probably go and use:

      publisher = apache.import_module("mod_python.publisher")

      instead. At least that way it will work all the time.

      I know my wanting to use internals of mod_python.publisher is the
      exception, but these sort of strange things shouldn't by right happen.

      Attachments

        1. package.diff.txt
          0.9 kB
          Graham Phillip Dumpleton

        Activity

          People

            Unassigned Unassigned
            grahamd Graham Phillip Dumpleton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: