diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py index 8798c05a01..324ba0f0c9 100644 --- a/django/contrib/comments/views/comments.py +++ b/django/contrib/comments/views/comments.py @@ -204,7 +204,7 @@ def post_comment(request): new_data = request.POST.copy() new_data['content_type_id'] = content_type_id new_data['object_id'] = object_id - new_data['ip_address'] = request.META['REMOTE_ADDR'] + new_data['ip_address'] = request.META.get('REMOTE_ADDR') new_data['is_public'] = comments.IS_PUBLIC in option_list response = HttpResponse() manipulator = PublicCommentManipulator(request.user, diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index c0e22dbb6a..00149ff791 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -79,7 +79,7 @@ class BaseHandler: if DEBUG: return self.get_technical_error_response() else: - subject = 'Database error (%s IP): %s' % ((request.META['REMOTE_ADDR'] in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) + subject = 'Database error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) message = "%s\n\n%s" % (self._get_traceback(), request) mail_admins(subject, message, fail_silently=True) return self.get_friendly_error_response(request, resolver) @@ -89,7 +89,7 @@ class BaseHandler: if DEBUG: return self.get_technical_error_response() else: - subject = 'Coding error (%s IP): %s' % ((request.META['REMOTE_ADDR'] in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) + subject = 'Coding error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) try: request_repr = repr(request) except: diff --git a/django/core/xheaders.py b/django/core/xheaders.py index 80210a25a0..98d2586b75 100644 --- a/django/core/xheaders.py +++ b/django/core/xheaders.py @@ -17,6 +17,6 @@ def populate_xheaders(request, response, package, python_module_name, object_id) within the INTERNAL_IPS setting. """ from django.conf.settings import INTERNAL_IPS - if request.META['REMOTE_ADDR'] in INTERNAL_IPS: + if request.META.get('REMOTE_ADDR') in INTERNAL_IPS: response['X-Object-Type'] = "%s.%s" % (package, python_module_name) response['X-Object-Id'] = str(object_id) diff --git a/django/middleware/doc.py b/django/middleware/doc.py index 8f648e0665..9345dbfcef 100644 --- a/django/middleware/doc.py +++ b/django/middleware/doc.py @@ -12,7 +12,7 @@ class XViewMiddleware: with an x-header indicating the view function. This is used by the documentation module to lookup the view function for an arbitrary page. """ - if request.META['REQUEST_METHOD'] == 'HEAD' and request.META['REMOTE_ADDR'] in settings.INTERNAL_IPS: + if request.META['REQUEST_METHOD'] == 'HEAD' and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS: response = httpwrappers.HttpResponse() response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__) return response