From 6eb1ac44527e40f26f078d336b4ad6838798432b Mon Sep 17 00:00:00 2001 From: Kristian Glass Date: Fri, 20 Jul 2012 18:50:04 +0100 Subject: [PATCH 1/2] Include response.content in raised HTTPErrors --- requests/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requests/models.py b/requests/models.py index 727654c8..e182ac34 100644 --- a/requests/models.py +++ b/requests/models.py @@ -821,16 +821,16 @@ class Response(object): raise self.error if (self.status_code >= 300) and (self.status_code < 400) and not allow_redirects: - http_error = HTTPError('%s Redirection' % self.status_code) + http_error = HTTPError('%s Redirection: %s' % (self.status_code, self.content)) http_error.response = self raise http_error elif (self.status_code >= 400) and (self.status_code < 500): - http_error = HTTPError('%s Client Error' % self.status_code) + http_error = HTTPError('%s Client Error: %s' % (self.status_code, self.content)) http_error.response = self raise http_error elif (self.status_code >= 500) and (self.status_code < 600): - http_error = HTTPError('%s Server Error' % self.status_code) + http_error = HTTPError('%s Server Error: %s' % (self.status_code, self.content)) http_error.response = self raise http_error From c485928a9f964632cd9556607889aeb1379846b8 Mon Sep 17 00:00:00 2001 From: Kristian Glass Date: Fri, 20 Jul 2012 19:26:08 +0100 Subject: [PATCH 2/2] Include reason rather than content in raised HTTPErrors See https://github.com/kennethreitz/requests/pull/733 for details, TL;DR content is too free-form for this to generally be a good idea. --- requests/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requests/models.py b/requests/models.py index e182ac34..0f8f423d 100644 --- a/requests/models.py +++ b/requests/models.py @@ -821,16 +821,16 @@ class Response(object): raise self.error if (self.status_code >= 300) and (self.status_code < 400) and not allow_redirects: - http_error = HTTPError('%s Redirection: %s' % (self.status_code, self.content)) + http_error = HTTPError('%s Redirection: %s' % (self.status_code, self.reason)) http_error.response = self raise http_error elif (self.status_code >= 400) and (self.status_code < 500): - http_error = HTTPError('%s Client Error: %s' % (self.status_code, self.content)) + http_error = HTTPError('%s Client Error: %s' % (self.status_code, self.reason)) http_error.response = self raise http_error elif (self.status_code >= 500) and (self.status_code < 600): - http_error = HTTPError('%s Server Error: %s' % (self.status_code, self.content)) + http_error = HTTPError('%s Server Error: %s' % (self.status_code, self.reason)) http_error.response = self raise http_error