[mod_python] Trapping output from importer.ReportError

Graham Dumpleton graham.dumpleton at gmail.com
Fri Mar 16 19:34:40 EST 2007

On 17/03/07, Chris Rilly <chrispwd at gmail.com> wrote:
> Hello,
> I have a custom logging class in our application that we use (writes to
> file, not to apache logs).
> What I would like to do is when an internal server error happens, log the
> traceback to the file via our logger and not the apache error log. I noticed
> in the importer module there is a method called "ReportError".  The exact
> output thats being emitted from that method is what I would like to capture.
> I'm somewhat new to mod_python, but is there a way to override or get the
> traceback from that method?


> My application is making use of the publisher
> handler.
> Off to the side a bit, after the traceback is logged, I would want to
> redirect the user to a specific page instead of the default "Internal server
> error" page.

The Apache way of doing things, which mod_python doesn't follow and
probably should be changed to conform to, is that the text of the
message it would display in the error page should also be stored in
req.notes['error-notes']. Having done that, all you need to do is

  ErrorDocument 500 /some/path/to/my/error/handler

The associated error handler would then be able to extract out
REDIRECT_ERROR_NOTES from the subprocess environment and use that in a
custom page.

If you have multilingual error documents enabled in Apache 2.X, they
already will display these error notes, but if you want a certain
format, you can just define your own error document handler as I

Anyway, to use this mechanism that Apache already supports is probably
the preferred way but mod_python has to be changed to use it.


More information about the Mod_python mailing list