From 7a0cd16c1a5be16f3df395ee12ed11d0ddde7837 Mon Sep 17 00:00:00 2001 From: Ravi Prakash Putchala Date: Wed, 9 Sep 2015 13:04:24 +0530 Subject: [PATCH] changed the null check for 'data' parameter to be more explicit. removed the superfluous encode from the testcase. --- requests/models.py | 2 +- test_requests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requests/models.py b/requests/models.py index 9fa367d3..06e84362 100644 --- a/requests/models.py +++ b/requests/models.py @@ -414,7 +414,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): content_type = None length = None - if not data and json is not None: + if data == {} and json is not None: content_type = 'application/json' body = complexjson.dumps(json) diff --git a/test_requests.py b/test_requests.py index fedf7293..87b47a19 100755 --- a/test_requests.py +++ b/test_requests.py @@ -1065,7 +1065,7 @@ class RequestsTestCase(unittest.TestCase): def test_json_param_post_should_not_override_data_param(self): r = requests.Request(method='POST', url='http://httpbin.org/post', data={'stuff'.encode('utf-8'): 'elixr'}, - json={'music'.encode('utf-8'): 'flute'}) + json={'music': 'flute'}) prep = r.prepare() assert 'stuff=elixr' == prep.body