From: Max Countryman Date: Fri, 9 Mar 2012 22:26:57 +0000 (-0500) Subject: potentially fixes #338 X-Git-Tag: v0.11.1~11^2~4^2~1^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bc5cc0dc92ae0b6edc356c90637a0d64e1d5042b;p=services%2Fpython-requests.git 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. --- diff --git a/requests/models.py b/requests/models.py index 753e83a..4bccb1e 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