Handle encoding of `None` when decoding unicode
authorMatt Sweeney <mattswe@gmail.com>
Tue, 25 Sep 2012 22:35:30 +0000 (15:35 -0700)
committerMatt Sweeney <mattswe@gmail.com>
Tue, 25 Sep 2012 22:35:30 +0000 (15:35 -0700)
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

index f33c3c3..305e615 100644 (file)
@@ -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