How can I send an email to admin when a 500 error occurs, in python.
The web framework I’m using is ‘bottle’.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just use the
@error(code)decorator to define an error handling page, like so:Just navigate to
/test_500to see it in actionYou can of course use a template for the error page just like with any other page. I’m not sure if there’s a way to get the built-in bottle error page while having an error handler.
Edit:
Apparently if you’re using the latest Bottle v0.8, the function to which you apply the
@errordecorator receives as a parameter not the error code, but anbottle.HTTPErrorobject, which contains the exception and traceback.Alternatively, you can set Bottle to not handle exceptions by setting
bottle.app().catchalltoFalseas described here, and then use some appropriate WSGI middleware to handle them and send the email (e.g. something like this).