Issue Details (XML | Word | Printable)

Key: MODPYTHON-12
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

ImportError: cannot import name publisher

Created: 28/Jan/05 06:01 PM   Updated: 05/Mar/06 01:37 PM
Return to search
Component/s: importer
Affects Version/s: 3.1.3
Fix Version/s: 3.2.7

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works package.diff.txt 2005-08-11 12:34 PM Graham Dumpleton 0.9 kB

Resolution Date: 22/Oct/05 04:36 PM


 Description  « Hide
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.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
No work has yet been logged on this issue.