繁体   English   中英

是否可以将Django的SafeExceptionReporterFilter与AdminEmailHandler一起使用?

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

我正在尝试使用Django的@sensitive_post_parameters过滤掉敏感信息。 我认为将这些注释添加到几个特定的​​功能上就足够了,但它不起作用。 我在SafeExceptionReporterFilter设置了断点,它只在从AdminEmailHandler不是其他处理程序调用时中断。 我错过了什么?

您可以编写使用django.views.debug.ExceptionReporter格式化异常的自定义处理程序。

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将使用DEFAULT_EXCEPTION_REPORTER_FILTER设置定义的ExceptionReporterFilter ,默认情况下为SafeExceptionReporterFilter

查看AdminEmailHandler实现,以获取有关如何创建自定义Handler

即使您使用SafeExceptionReporterFilter ,异常仍将包含敏感数据(例如,您的服务器的ENV变量和其他运行时数据)。

为避免暴露敏感数据,您不应使用此过滤器。 相反,编写自己的异常处理程序中间件并有选择地(递归地?)从日志中获取所需的数据。

请参阅sys.exc_info ,了解如何获取异常的回溯以及如何根据需要使用它。

即使你使用CustomHandler,你也会受到特定处理程序的限制,据我所知,第三方处理程序不会使用SafeExceptionReporterFilter

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM