[mod_python] Returning HTTP_MULTI_STATUS from a custom handler

Gregory (Grisha) Trubetskoy grisha at modpython.org
Mon Jun 14 14:24:19 EDT 2004


If you want Apache to handle the error, you return it the error code. This
will result in the behaviour you are seeing (an error page and a status of

If you do not want Apache to handle the error (and in your case you do
not), then set req.status yourself, write the necessary output (e.g. some
html describing the error)  if any, and return apache.OK.

So the code you're looking for is:

def handler(req):
    req.status = apache.HTTP_MULTI_STATUS
    req.content_type = 'text/plain; charset=UTF-8"
    return apache.OK

This may seem confusing at first, but if you think about it it actually
makes pretty good sense. :-)


On Mon, 14 Jun 2004, Indrek [ISO-8859-1] J?rve wrote:

> Hi,
> I'm currently working on creating a WebDAV implementation in mod_python.
> To achieve this, I've written a custom request handler which does the
> work required for each request and returns the defined status code
> according to WebDAV spec. However, whenever I try to return
> apache.HTTP_MULTI_STATUS (required by some response types), something
> funky happens. A standard apache "internal error occured" gets appended
> to the client output, and apache return code gets changed to 200. It's
> rather easy to duplicate, a minimal handler like below reproduces it on
> my Suse 9.0/mod_python 3.0 box.
> TestPublisher.py:
> from mod_python import apache
> def handler(req):
>     req.content_type = 'text/plain; charset=UTF-8"
>     req.write('hi!')
>     return apache.HTTP_MULTI_STATUS
> Am I doing something awfully wrong or is this a general problem?
> Regards,
> Indrek
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list