From 2bb49ff386deab4e67e199450085720c1521411a Mon Sep 17 00:00:00 2001 From: Matt Sweeney Date: Tue, 25 Sep 2012 15:35:30 -0700 Subject: [PATCH] Handle encoding of `None` when decoding unicode If encoding is None, decoding will throw the following TypeError: TypeError: unicode() argument 2 must be string, not None If this is the case, attempt to run without any set encoding --- requests/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/requests/models.py b/requests/models.py index f33c3c3e..305e615e 100644 --- a/requests/models.py +++ b/requests/models.py @@ -834,6 +834,11 @@ class Response(object): # # 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. + content = str(self.content, errors='replace') return content