From bc5cc0dc92ae0b6edc356c90637a0d64e1d5042b Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Fri, 9 Mar 2012 17:26:57 -0500 Subject: [PATCH] potentially fixes #338 This attempts to fix an issue where encoding of a string might fail when the encoding is set to some unknown format. Here we attempt to catch the LookupException and subsequently blindly encode the string one final time. That is we call str() over response.content without specifying an encoding. This may still fail in certain cases but does properly handle the case of #338 by returning the expected string. --- requests/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requests/models.py b/requests/models.py index 753e83ab..4bccb1e3 100644 --- a/requests/models.py +++ b/requests/models.py @@ -788,6 +788,9 @@ class Response(object): # Decode unicode from given encoding. try: content = str(self.content, encoding, errors='replace') + except LookupError: + # try blindly encoding + content = str(self.content, errors='replace') except (UnicodeError, TypeError): pass