[mod_python] capturing and handling python errors in mod_python

Waitman Gobble waitman at waitman.net
Mon Nov 14 12:30:56 EST 2005


Hello,

I am new to mod_python and am interested in catching python errors with a
default error handler.

For example, http://pyblog.com/index/causeanerror


def causeanerror(req):
    asdlkfj



would not barf on the user, it would send the error to my error function
or something.


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



Interestingly, if I do a

# HEAD http://pyblog.com/

I receive:

405 Method Not Allowed
Connection: close
Date: Mon, 14 Nov 2005 17:23:42 GMT
Server: Apache/2.0.55 (Unix) mod_ssl/2.0.55 OpenSSL/0.9.8a PHP/4.4.1
mod_python/3.1.4 Python/2.4.2
Allow: GET,HEAD,POST,TRACE
Content-Type: text/html; charset=iso-8859-1
Client-Date: Mon, 14 Nov 2005 17:23:42 GMT
Client-Peer: 6.13.7.17.5:80
Client-Response-Num: 1

<?> Why does a HEAD request return a 405 but "Allow:" says "HEAD" is cool?


If I do a

# GET -s http://pyblog.com/

that works returning a 200


if I do a

# GET -s http://pyblog.com/index/causeanerror

it ALSO returns a status code of 200 OK with the python error. So catching
it in apache (presuming that mod_python would return a 500 error -
wouldn't that be nice?) with ErrorDocument doesn't seem likely to function
properly.


I appreciate your comments and suggestions.

Bye,

Waitman




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



More information about the Mod_python mailing list