Many more details on import weirdness (was: Re: [mod_python] Severe problems with importing still happening.)

Sean Reifschneider jafo at
Thu Sep 2 02:36:38 EDT 2004

On Mon, Aug 30, 2004 at 10:52:32AM -0400, Gregory (Grisha) Trubetskoy wrote:
>I've skimmed over the two messages you referenced, and it wasn't very 
>apparent what the problem is mainly due to the complexity of the 
>attributes. I think if you want this resolved, you need to work on a clean 

Ok, I've finally been able to reproduce the problem in a simple example.
Here's what I did:

   Add the following to my httpd.conf:

      Listen *:8084

      #  for debugging
      MaxKeepAliveRequests 1
      MaxRequestsPerChild  1

      <VirtualHost *:8084>
         ServerAdmin webmaster at
         DocumentRoot /home/httpd/modpythonpublishertest/py/

         PythonAutoReload On
         PythonDebug On

         <Directory /home/httpd/modpythonpublishertest/py/>
            AddHandler mod_python .py
            PythonHandler foo::handler


      def handler(req):
         #from mod_python import util
         import mod_python
         from package import module


      import module


      import mod_python

      def function(request):

Now, restart Apache and access  The
following is displayed:

   Mod_python error: "PythonHandler foo::handler"

   Traceback (most recent call last):

     File "/usr/lib/python2.3/site-packages/mod_python/", line
   299, in HandlerDispatch
       result = object(req)

     File "/home/httpd/modpythonpublishertest/py/", line 5, in

     File "/home/httpd/modpythonpublishertest/py/package/", line
   4, in function

   AttributeError: 'module' object has no attribute 'util'

If you uncomment the line "#from mod_python import util" from and
reload the URL, it will display:


Unfortunately, the patch which "Byron Ellacott <bje at>" posted
about a couple of days ago I can confirm does *NOT* resolve this issue.
Though it definitely sounds like a similar issue.

It seems to me that the information I posted back in May of 2004 in:

has some fairly important information, it's just that it means nothing
to me.  In particular:

   <module 'jotweb.jotwebutils' from
      '/var/www/jotweb/www.tummy.jotweb.jotwebutils' from

In other words, it seems to have a weird path in one of the modules.
Note that in this case, "/var/www/jotweb/" was
probably my DocumentRoot.

Note that in my testing tonight, I tried augmenting, and it seems to only get called for "foo",
not for mod_pyhon, of course.  I added some logging of the above, and
they're both coming up as "module 'mod_python'".  However, if I take a
dir() of it, I see that if I leave the line commented I get:

   ['__all__', '__builtins__', '__doc__', '__file__', '__name__',
   '__path__', 'apache']

and if I uncomment it I get:

   ['__all__', '__builtins__', '__doc__', '__file__', '__name__',
   '__path__', 'apache', 'util']

I believe this is fairly close to what I've seen elsewhere.  This case I
can't really reproduce outside of mod_python, but others I could.  In
other words, it was my own code that was having this problem in the
past, but if I ran the same code outside of mod_python, it would run

That's about all I know.  It seems like some sort of interaction, where
something mod_python is doing is causing something weird to happen with
standard Python imports.

 Thieves broke into Scotland Yard yesterday and stole all the toilets.
 Detectives say they have nothing to go on.
Sean Reifschneider, Member of Technical Staff <jafo at>, ltd. - Linux Consulting since 1995.  Qmail, Python, SysAdmin

More information about the Mod_python mailing list