diff --git a/requests/compat.py b/requests/compat.py index 8e4a17e4..af0207de 100644 --- a/requests/compat.py +++ b/requests/compat.py @@ -91,6 +91,7 @@ if is_py2: from StringIO import StringIO from .packages import chardet + builtin_str = str bytes = str str = unicode basestring = basestring @@ -105,6 +106,7 @@ elif is_py3: from io import StringIO from .packages import chardet2 as chardet + builtin_str = str str = str bytes = bytes basestring = (str,bytes) diff --git a/requests/models.py b/requests/models.py index 9b248d31..514bcb40 100644 --- a/requests/models.py +++ b/requests/models.py @@ -32,7 +32,7 @@ from .utils import ( DEFAULT_CA_BUNDLE_PATH) from .compat import ( cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes, - StringIO, is_py2, chardet, json) + StringIO, is_py2, chardet, json, builtin_str) REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved) CONTENT_CHUNK_SIZE = 10 * 1024 @@ -507,7 +507,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' diff --git a/tests/test_requests.py b/tests/test_requests.py index 076ca6ce..6fe0d758 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1029,5 +1029,12 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase): self.assertEqual(t.get('form'), {'field': 'a, b'}) self.assertEqual(t.get('files'), files) + def test_str_data_content_type(self): + data = 'test string data' + r = post(httpbin('post'), data=data) + t = json.loads(r.text) + self.assertEqual(t.get('headers').get('Content-Type'), '') + + if __name__ == '__main__': unittest.main()