Include reason rather than content in raised HTTPErrors
authorKristian Glass <git@doismellburning.co.uk>
Fri, 20 Jul 2012 18:26:08 +0000 (19:26 +0100)
committerKristian Glass <git@doismellburning.co.uk>
Fri, 20 Jul 2012 18:26:08 +0000 (19:26 +0100)
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

index e182ac34510368476d2ea8ee8a27a90e19449d34..0f8f423d474881ce927894ea9b10ff6597cc817d 100644 (file)
@@ -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