diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py index db3c33147b..41d9a578c5 100644 --- a/django/core/handlers/modpython.py +++ b/django/core/handlers/modpython.py @@ -16,9 +16,26 @@ class ModPythonRequest(http.HttpRequest): self.path = req.uri def __repr__(self): + # Since this is called as part of error handling, we need to be very + # robust against potentially malformed input. + try: + get = pformat(self.GET) + except: + get = '' + try: + post = pformat(self.POST) + except: + post = '' + try: + cookies = pformat(self.COOKIES) + except: + cookies = '' + try: + meta = pformat(self.META) + except: + meta = '' return '' % \ - (self.path, pformat(self.GET), pformat(self.POST), pformat(self.COOKIES), - pformat(self.META)) + (self.path, get, post, cookies, meta) def get_full_path(self): return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '') diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py index 87e67e9c5b..85e234c8d2 100644 --- a/django/core/handlers/wsgi.py +++ b/django/core/handlers/wsgi.py @@ -78,9 +78,26 @@ class WSGIRequest(http.HttpRequest): self.method = environ['REQUEST_METHOD'].upper() def __repr__(self): + # Since this is called as part of error handling, we need to be very + # robust against potentially malformed input. + try: + get = pformat(self.GET) + except: + get = '' + try: + post = pformat(self.POST) + except: + post = '' + try: + cookies = pformat(self.COOKIES) + except: + cookies = '' + try: + meta = pformat(self.META) + except: + meta = '' return '' % \ - (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES), - pformat(self.META)) + (get, post, cookies, meta) def get_full_path(self): return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')