[ http://issues.apache.org/jira/browse/MODPYTHON-12?page=all ]

Nicolas Lehuen updated MODPYTHON-12:
------------------------------------

    Component: importer

> ImportError: cannot import name publisher
> -----------------------------------------
>
>          Key: MODPYTHON-12
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-12
>      Project: mod_python
>         Type: Bug
>   Components: importer
>     Versions: 3.1.3
>     Reporter: Graham Dumpleton
>  Attachments: package.diff.txt
>
> 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.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to