Simplify error handling when decoding unicode
authorMatt Sweeney <mattswe@gmail.com>
Wed, 26 Sep 2012 19:38:36 +0000 (12:38 -0700)
committerRadu Voicilas <radu.voicilas@gmail.com>
Mon, 8 Oct 2012 21:42:48 +0000 (00:42 +0300)
requests/models.py

index 305e615..2193c6e 100644 (file)
@@ -828,13 +828,10 @@ class Response(object):
         # Decode unicode from given encoding.
         try:
             content = str(self.content, encoding, errors='replace')
-        except LookupError:
+        except (LookupError, TypeError):
             # A LookupError is raised if the encoding was not found which could
             # indicate a misspelling or similar mistake.
             #
-            # So we try blindly encoding.
-            content = str(self.content, errors='replace')
-        except TypeError:
             # A TypeError can be raised if encoding is None
             #
             # So we try blindly encoding.