Skip to content
Myr

Merge pull request #805 from Lukasa/develop

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

Remove None values from post data.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 4571a9e, 751e7a0 · Browse files · 2 files+14 added−3 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+14 added−3 removed

  • tests:+10 added−0 removed
  • other:+4 added−3 removed

2 files+14 added−3 removed

modified:requests/models.py+4 added-3 removed
328 unmodified lines
329 elif hasattr(data, '__iter__'):330 result = []331 for k, vs in to_key_val_list(data):332 for v in isinstance(vs, list) and vs or [vs]:333 if v is not None:333 result.append(334 (k.encode('utf-8') if isinstance(k, str) else k,335 v.encode('utf-8') if isinstance(v, str) else v))334 result.append(335 (k.encode('utf-8') if isinstance(k, str) else k,336 v.encode('utf-8') if isinstance(v, str) else v))337 return urlencode(result, doseq=True)338 else:339 return data340
545 unmodified lines
modified:tests/test_requests.py+10 added
1110 unmodified lines
1111 """Test that URLs with invalid labels throw1112 Requests.exceptions.InvalidURL instead of UnicodeError."""1113 self.assertRaises(InvalidURL, get, 'http://.google.com/')11141115 def test_none_vals_in_data_are_deleted(self):1116 """Test that keys with None as the value are removed instead of1117 being posted."""1118 data = {'key1': 'value1', 'key2': None}1119 r = post(httpbin('post'), data=data)1120 vals = r.json['form']1121 self.assertEqual(vals['key1'], 'value1')1122 # The 'key2' key should not have been sent.1123 self.assertTrue(vals.get('key2') is None)11241125if __name__ == '__main__':1126 unittest.main()