Updated: (MODPYTHON-12) ImportError: cannot import name publisher
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Mod-Python > Updated: (MODPYTHON-12) ImportError: cannot import name publisher




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Updated: (MODPYTHON-12) ImportError: cannot import name publisher  
Graham Dumpleton (JIRA)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-11-05 07:48 AM

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

Graham Dumpleton updated MODPYTHON-12:
--------------------------------------

Attachment: package.diff.txt

An even simpler test for this problem is to use a publisher function defined
 as:

import mod_python

def index(req):
from mod_python import publisher
req.content_type = 'text/plain'
return "index %r" % dir(mod_python)

When "from mod_python import publisher" is executed it will complain it cann
ot find "publisher".

I have attached a fix for this problem, which hopefully can be added to 3.2.

I think this is the last problem I know of where I keeping having to use a w
orkaround.

BTW, this is [ISSUE 6] in my article about module import problems:

http://www.dscpl.com.au/articles/mo...-loaded-wrongly

I might go through my list and see what other things might easily be fixed f
or 3.2. :-)


> ImportError: cannot import name publisher
> -----------------------------------------
>
>          Key: MODPYTHON-12
>          URL: http://issues.apache.org/jira/browse/MODPYTHON-12
>      Project: mod_python
>         Type: Bug
>     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/pyt
hon2.3/site-packages/mod_python/apache.py", line 296, in HandlerDispatch
>       log=debug)
>     File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/pyt
hon2.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/pyt
hon2.3/site-packages/mod_python/apache.py", line 474, in _unsafe_import_modu
le
>       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.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:01 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register