Skip to content
Myr

Fixed issue #2756

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Now 'json' parameter will be used to prepare body only if the 'data' parameter is not present

authored by Ravi Prakash Putchala · committed by Ravi Prakash Putchala · parent 56ecdeb · Browse files · 2 files+9 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−2 removed

  • other:+9 added−2 removed

2 files+9 added−2 removed

modified:requests/models.py+2 added-2 removed
412 unmodified lines
413 body = None414 content_type = None415 length = None416417 if json is not None:417 if not data and json is not None:418 content_type = 'application/json'419 body = complexjson.dumps(json)420421 is_stream = all([
20 unmodified lines
442 # Multi-part file uploads.443 if files:444 (body, content_type) = self._encode_files(files, data)445 else:446 if data and json is None:446 if data:447 body = self._encode_params(data)448 if isinstance(data, basestring) or hasattr(data, 'read'):449 content_type = None450 else:
398 unmodified lines
modified:test_requests.py+7 added
1060 unmodified lines
1061 assert r.status_code == 2001062 assert 'application/json' in r.request.headers['Content-Type']1063 assert {'life': 42} == r.json()['json']10641065 def test_json_param_post_should_not_override_data_param(self):1066 r = requests.Request(method='POST', url='http://httpbin.org/post',1067 data={'stuff'.encode('utf-8'): 'elixr'},1068 json={'music'.encode('utf-8'): 'flute'})1069 prep = r.prepare()1070 assert 'stuff=elixr' == prep.body10711072 def test_response_iter_lines(self):1073 r = requests.get(httpbin('stream/4'), stream=True)1074 assert r.status_code == 2001075
609 unmodified lines