From aad3bc6005178c03794a36dd81b66144eb116761 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Sat, 9 Dec 2017 14:02:08 -0400 Subject: [PATCH] Add request.META to error mail --- scipost/views.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/scipost/views.py b/scipost/views.py index 0b55b078c..8aaa124d1 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -1,4 +1,4 @@ -import logging +import json from django.utils import timezone from django.shortcuts import get_object_or_404, render @@ -1328,15 +1328,21 @@ def csrf_failure(request, reason=""): Custom CRSF Failure. Informing admins via email as well. """ # Filter out privacy data - settings_dict = {} - + post_data = {} for key in request.POST.keys(): if key: - settings_dict[key] = cleanse_setting(key, request.POST[key]) + post_data[key] = cleanse_setting(key, request.POST[key]) # Email content - body = 'Error message: ' + reason + '\nUser: ' + str(request.user) - body += '\nRequest GET: ' + str(request.GET) + '\nRequest POST: ' - body += str(settings_dict) + body = { + 'ERROR': str(reason), + 'USER': str(request.user), + 'GET': dict(request.GET), + 'POST': post_data, + 'META': {k: str(v) for k, v in request.META.items()}, + } + + body = json.dumps(body, indent=4) + mail.mail_admins('CRSF Failure', body) return render(request, 'crsf-failure.html') -- GitLab