[mod_python] Various simple questions. I hope.

Bart scarfboy at gmail.com
Sun Jan 29 16:47:25 EST 2006

Hey all.

Question. When I write:
    def requesthandler(req):
        req.content_type = "text/plain"
        req.write("Hello World!")
        return apache.OK
...it returns "Hello World!0", so that style will
corrupt particularly my non-HTML data, so I don't
use it. Thing is, it's copy-pasted from 3.1(.3)
documentation and I have 3.1.4 (-r1, in gentoo).

So is this a difference between using AddHandler
python-program and AddHandler mod_python?
Or do the docs accidentally describe 3.2 or and old
version?   (I use:
  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug On
Is this unusual?)

It also leaves me a little baffled on what I should
return from a handler function. My code works,
I just don't know whether it should be written
the way it is.

People discuss apache.OK, and the difference
between it and apache.DONE and such, so I'm
guessing this is current code - but apparently
it works differently under publisher. Or my version.

It also left me confused about how to handle
success and errors.

It seems like you're suppose to return simple ones
and raise things on specific errors when you want
apache to use its error pages - but apparently
you set req.status for other cses yet, because where
does this leave things like the 304?
I use  req.status=apache.HTTP_NOT_MODIFIED
elsewhere to handle my manual ETags on
dynamically served images. Despite me just having
read that setting req.status doesn't actually do
anything, my header snooper tells me it does in
fact work. Reading somewhere else says it works,
is the way it should work, and should probably be
followed by a return apache.DONE.
But since that doesn't seem to apply to me, what
do I do? How do I get these apache.THINGS, since
they seem to be the way thing work for other people?

Am I just missing something obvious?

Also, because of the empty-string problem,
I had to return something (I chose a space) instead of
nothing, which I'm not sure is entirely up to HTTP specs
since the RFC tells me "The 304 response MUST NOT
contain a message-body"
What's the better way of doing this?

("empty-string problem": Returning an empty string after
  writing no data leads to borking out with 500/Internal Server
  Error, and a "funtion x returned no data" error in the logs.
  I'm guessing this is accepted, or at least expected behaviour,
  though I'd prefer if that only happened on return None
  (and implicitly on a lack of a return), but not on return "")

So I suppose my real question is "Is there a nice overview
of the varying behaviour under different versions and different
PyhonHandlers, particularly the current?" Should I not be
using the publisher, since it seems to contradict the docs?

*If* I'm going to have to know a few innards to use mod_python
so be it, but right now I have a fragile environment with
no simple way of telling what'll work without testing it.

And I don't like to bug you guys too much with this sort
of "huh, what? wah!", y'know :)

Thanks for your time,
--Bart Alewijnse

More information about the Mod_python mailing list