[mod_python] mod_python weirdness, maybe related to importing?

Sean Reifschneider jafo at tummy.com
Tue Jun 10 02:14:22 EST 2003

On Tue, Jun 10, 2003 at 09:12:46AM +0200, David Fraser wrote:
>Do you mean you're using this import mechanism when you have the problem 
>with jotweb.input.Request below?

I mean that the imp module call is loading a module which then does an
"import jotweb.input".  If in the jotweb I don't have the __init__.py
import all sub-packages or sub-modules, I will get an AttributeError
such as:

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

>>  import Request
>Have you tried using __all__ = [Request, ...] in __init__.py ?

I believe I did try that at one point, but it's my understanding that
setting "__all__" only has an impact if you do "from jotweb import *",
which I don't do anywhere.  Also, as I said before, I can import the
code fine outside of mod_python.  "python -c 'import jotweb.input'", for

>mod_python does have some import hooks to handle things specially, but 
>I'm not an expect here, someone else will have to comment...

I wonder if I'm running into something there.  I've tried simplifying it

   include current directory in path
   module = __import__(basename, globals(), locals(), [])
   return sys.path to old layout

that doesn't really seem to help the problem with imports though...

>How do you pass the request object into processLogin (it doesn't seem to 
>be part of the call)?
>It seems like you may be trying to use an old request object or something...

The request object is stored into a module, where other parts of my
system will pick it up when they need either the headers or the request.

I've verified that the id() of the header_out object is the same in the
higher-level and lower-level code.  I'm not calling request.write()
anywhere except at the end of my top-level code, nor am I doing a print
anywhere.  I guess it might be a problem with SimpleTAL?  It's not going
to access the Apache request object, but maybe it's doing a print?

>No. But it is a bit more complex running a python interpreter inside 
>Apache than standalone.

Sure, I understand that, and I'm ok with it being more complicated.  I'm
just not happy about running into sporadic problems where sometimes
things work, sometimes they don't.

For example, *ANY* time I submit a request for a URL via a telnet
connection, I get the headers back:

   guin:jafo$ telnet 80
   Connected to
   Escape character is '^]'.
   GET HTTP/1.0

   HTTP/1.0 200 OK
   Date: Tue, 10 Jun 2003 08:10:44 GMT
   Server: Apache/2.0.40 (Red Hat Linux)
   Set-cookie: sessionid=20d315c26c8c395e61730ceb27d0faa98fd; Comment="User Login Cookie"; Path=/; Version=1;
   Cache-control: max-age=0
   Expires: Thu, 01 Dec 1994 16:00:00 GMT
   Content-Length: 405
   Connection: close
   Content-Type: text/html; charset=ISO-8859-1


If I paste the URL:

into Konqueror, the headers I'm getting back are:

   Date: Tue, 10 Jun 2003 08:10:44 GMT
   Server: Apache/2.0.40 (Red Hat Linux)
   Connection: close
   Content-Type: text/html; charset=ISO-8859-1

(according to Konqueror).  I've tried Mozilla and galeon as well, all
with similar results.  Yes, I have cookies enabled from localhost.  If I
put the headers_out.add() at the top of my handler, it showes up in
Konqueror's "View Page Info" output...

 Do you think reading about cowboys is sufficient to ride a horse?
 Like horses, real programs tend to throw you.  -- John Shipman, 1997
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995.  Qmail, Python, SysAdmin

More information about the Mod_python mailing list