[mod_python] capturing and handling python errors in mod_python

Waitman Gobble waitman at waitman.net
Mon Nov 14 14:00:44 EST 2005


A few more comments.

If I use PythonDebug Off then the errors still go to the client anyhow.
Reading the doc leads me to believe that this isn't what should be
expected.

If I Use PythonLogHandler (conf example below) then I might be able to
catch uncaught exceptions, but I can't figure out how to obliterate
anything outgoing located in the request object. Writing to it appends, is
there a way to totally empty or replace the buffer?

I tried something like

http://pyblog.com/doit/good

def good(req):
    req.proposed_output="THIS IS IT"
    return ""

and
http://pyblog.com/doit/naughty

def naughty(req):
    awelkfjawlkefjaklwejf


then my logging function in log.py

def logger(req):
    the_content="ERROR!"
    try:
        if (req.proposed_content!=""):
            the_content=req.proposed_content
        else:
            the_content="It can't happen here"
    finally:
        req.write(the_content)
    return apache.OK



<?> one thing I've noticed is that ALL requests go to PythonLogHandler
regardless of my "Files SetHandler None" directive."

If I put
    file = open("/home/wwweb/pyblog/log/output.txt", "at")
    file.write(str(req.the_request)+"\t"+str(req.status)+"\n");
    file.close()

in my index.py then I get this in output.txt

GET / HTTP/1.1  200
GET / HTTP/1.1  200
GET / HTTP/1.1  200



if I put the same thing in log.py then I get this stuff:

GET / HTTP/1.1  200
GET /css/548xAF.css HTTP/1.1    304
GET /images/pyblog.png HTTP/1.1 304

Why are the requests for PNG, CSS etc going to log.py???


        <Directory "/home/wwweb/pyblog/htdocs">
            SetHandler mod_python
            PythonHandler mod_python.publisher
            PythonDebug Off
            PythonLogHandler log::logger
            Options none
            AllowOverride none
            Allow from all
                <Files ~ "\.(gif|jpe?g|png|html?|css|js)$">
                        SetHandler None
                </Files>
                <Files *.pyc>
                        Deny from all
                </Files>
        </Directory>

-- 
Waitman Gobble
http://waitman.net/
(707) 237-6921



More information about the Mod_python mailing list