Skip to content
Myr

requests.post checked data parameters for type like dict.

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

Changed the type check to Mapping.

authored by Philipp Konrad · committed by Philipp Konrad · parent 50486cf · Browse files · 3 files+28 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

3 files+28 added−2 removed

  • tests:+25 added−0 removed
  • other:+3 added−2 removed

3 files+28 added−2 removed

modified:requests/models.py+1 added-1 removed
434 unmodified lines
435 body = body.encode('utf-8')436437 is_stream = all([438 hasattr(data, '__iter__'),439 not isinstance(data, (basestring, list, tuple, dict))439 not isinstance(data, (basestring, list, tuple, collections.Mapping))440 ])441442 try:443 length = super_len(data)
439 unmodified lines
modified:tests/test_requests.py+25 added
654 unmodified lines
655656 with pytest.raises(ValueError):657 requests.post(url, files=['bad file data'])658659 def test_post_with_custom_mapping(self, httpbin):660 class CustomMapping(collections.MutableMapping):661 def __init__(self, *args, **kwargs):662 self.data = dict(*args, **kwargs)663664 def __delitem__(self, key):665 del self.data[key]666667 def __getitem__(self, key):668 return self.data[key]669670 def __setitem__(self, key, value):671 self.data[key] = value672673 def __iter__(self):674 return iter(self.data)675676 def __len__(self):677 return len(self.data)678679 data = CustomMapping({'some': 'data'})680 url = httpbin('post')681 found_json = requests.post(url, data=data).json().get('form')682 assert found_json == {'some': 'data'}683684 def test_conflicting_post_params(self, httpbin):685 url = httpbin('post')686 with open('requirements.txt') as f:687 pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})")
1276 unmodified lines
modified:AUTHORS.rst+2 added-1 removed
168 unmodified lines
169- Nate Prewitt <nate.prewitt@gmail.com> (`@nateprewitt <https://github.com/nateprewitt>`_)170- Maik Himstedt171- Michael Hunsinger172- Brian Bamsch <bbamsch32@gmail.com> (`@bbamsch <https://github.com/bbamsch>`_)173- Om Prakash Kumar <omprakash070@gmail.com> (`@iamprakashom <https://github.com/iamprakashom>`_)173- Om Prakash Kumar <omprakash070@gmail.com> (`@iamprakashom <https://github.com/iamprakashom>`_)174- Philipp Konrad <gardiac2002@gmail.com> (`@gardiac2002 <https://github.com/gardiac2002>`_)