Merge pull request #2763 from ravipra/json_supersedes

Fixed issue #2756
This commit is contained in:
Cory Benfield
2015-10-05 15:27:53 +01:00
2 changed files with 9 additions and 2 deletions
+2 -2
View File
@@ -414,7 +414,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
content_type = None
length = None
if json is not None:
if data == {} and json is not None:
content_type = 'application/json'
body = complexjson.dumps(json)
@@ -443,7 +443,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
if files:
(body, content_type) = self._encode_files(files, data)
else:
if data and json is None:
if data:
body = self._encode_params(data)
if isinstance(data, basestring) or hasattr(data, 'read'):
content_type = None
+7
View File
@@ -1082,6 +1082,13 @@ class RequestsTestCase(unittest.TestCase):
assert 'application/json' in r.request.headers['Content-Type']
assert {'life': 42} == r.json()['json']
def test_json_param_post_should_not_override_data_param(self):
r = requests.Request(method='POST', url='http://httpbin.org/post',
data={'stuff': 'elixr'},
json={'music': 'flute'})
prep = r.prepare()
assert 'stuff=elixr' == prep.body
def test_response_iter_lines(self):
r = requests.get(httpbin('stream/4'), stream=True)
assert r.status_code == 200