Full sample code. If I comment '1/0' everything works fine. If I uncomment 
this string, which throws an exception, an HTTP response 500 is returned to 
web client, and mod_wsgi puts in web server logs standard error trace 
(standard unmodified sys.excepthook's behavior).

import sys 

def application(environ, start_response): 
    def exception(etype, evalue, trace): 
        start_response('200 OK', [('Content-Type', 'text/plain')]) 
        return ['Error'] 

    sys.excepthook = exception 

    1/0 

    start_response('200 OK', [('Content-Type', 'text/plain')]) 
    return ['OK'] 

On Wednesday, February 18, 2015 at 10:03:48 AM UTC+3, Alexander Sh wrote:
>
>
>
> <http://stackoverflow.com/questions/28570523/handling-exceptions-under-mod-wsgi-assigning-to-sys-excepthook-doesnt-work#>
>  
>   
> I want to generate an html page with http response status '200 OK' in case 
> of an uncaught exception in my wsgi application, instead of web server's 
> standard '500 Internal Server Error' response for such case. To do so, I've 
> made the following sample code:
>
> def application(environ, start_response):
>     def exception(etype, evalue, trace):
>         start_response('200 OK', [('Content-Type', 'text/plain')])
>         return ['Error']
>
>     sys.excepthook = exception
>
>     ...
>
>
> But the function 'exception' is never called, and a standard '500 Internal 
> Server Error' response is still generated by server in case of an uncaught 
> exception.
>
> I looked through the documentation, but unable to find the answer. Are 
> there any ways to handle uncaught by try..except exceptions under mod_wsgi?
>

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to