only try to decode if self.encoding is set
authorKenneth Reitz <me@kennethreitz.com>
Sat, 21 Jan 2012 06:28:26 +0000 (01:28 -0500)
committerKenneth Reitz <me@kennethreitz.com>
Sat, 21 Jan 2012 06:28:26 +0000 (01:28 -0500)
requests/models.py

index 5da4d7e..c116e36 100644 (file)
@@ -711,19 +711,19 @@ class Response(object):
         """Content of the response, in unicode."""
 
         # Try charset from content-type
-
         content = u''
 
-        try:
-            content = unicode(self.content, self.encoding)
-        except UnicodeError:
-            pass
+        if self.encoding:
+            try:
+                content = unicode(self.content, self.encoding)
+            except UnicodeError:
+                pass
 
-        # Try to fall back:
-        try:
-            content = unicode(content, self.encoding, errors='replace')
-        except TypeError:
-            pass
+            # Try to fall back:
+            try:
+                content = unicode(content, self.encoding, errors='replace')
+            except TypeError:
+                pass
 
         return content