Fixed issue #747
authorMarcus McCurdy <marcus.mccurdy@gmail.com>
Sat, 4 Aug 2012 03:13:17 +0000 (23:13 -0400)
committerMarcus McCurdy <marcus.mccurdy@gmail.com>
Sat, 4 Aug 2012 03:13:17 +0000 (23:13 -0400)
Bound the name builtin_str to __builtin__.str and added another check
for this class since the str class was rebound to unicode in compat.
This issue was only for Python 2 as well.

requests/models.py
tests/test_requests.py

index 490073723b6caf8d2b35de1cea01452e89f62e78..970acf8a67f410c7579aea24764e8c5f5734cddd 100644 (file)
@@ -34,6 +34,8 @@ from .compat import (
     cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,
     StringIO, is_py2, chardet, json)
 
+from __builtin__ import str as builtin_str
+
 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)
 CONTENT_CHUNK_SIZE = 10 * 1024
 
@@ -493,7 +495,7 @@ class Request(object):
             if self.data:
 
                 body = self._encode_params(self.data)
-                if isinstance(self.data, str) or hasattr(self.data, 'read'):
+                if isinstance(self.data, str) or isinstance(self.data, builtin_str) or hasattr(self.data, 'read'):
                     content_type = None
                 else:
                     content_type = 'application/x-www-form-urlencoded'
index 10da6f7e1842413e6e9e1fdfd15376de48a41141..9204b15dc8f673c7de5dffb99e6e143efb06dfbd 100755 (executable)
@@ -974,10 +974,10 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
         self.assertEqual(t.get('files'), files)
 
     def test_str_data_content_type(self):
-        data = "test string data"
+        data = 'test string data'
         r = post(httpbin('post'), data=data)
         t = json.loads(r.text)
-        self.assertEqual(t.get('headers').get('Content-Type'), 'text/plain')
+        self.assertEqual(t.get('headers').get('Content-Type'), '')
 
 
 if __name__ == '__main__':