Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Django's SafeExceptionReporterFilter with something else than the AdminEmailHandler?

I'm trying to filter out sensitive informations using Django's @sensitive_post_parameters. I thought prepending these annotations over a the few specific fonctions would be enough, but it doesn't work. I've set breakpoint inside SafeExceptionReporterFilter and it only breaks when being called from the AdminEmailHandler and not the other handlers. What am I missing ?

like image 970
Laurent Jalbert Simard Avatar asked Apr 16 '15 15:04

Laurent Jalbert Simard


1 Answers

You can write a custom Handler that uses django.views.debug.ExceptionReporter to format the exception.

Example use of ExceptionReporter:

from django.views.debug import ExceptionReporter

# exc_type, exc_value, traceback are a standard exception
# tuple as returned by sys.exc_info
reporter = ExceptionReporter(request, exc_type, exc_value, traceback)
html_report = reporter.get_traceback_html()
text_report = reporter.get_traceback_text()

ExceptionReporter will use the ExceptionReporterFilter defined by the DEFAULT_EXCEPTION_REPORTER_FILTER setting which by default is SafeExceptionReporterFilter.

Have a look at AdminEmailHandler's implementation to get info on how to create a custom Handler.

like image 184
aumo Avatar answered Oct 20 '22 01:10

aumo