diff --git a/AUTHORS.rst b/AUTHORS.rst index 1b4d3c2b..9e068eb8 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -170,4 +170,5 @@ Patches and Suggestions - Maik Himstedt - Michael Hunsinger - Brian Bamsch (`@bbamsch `_) -- Om Prakash Kumar (`@iamprakashom `_) \ No newline at end of file +- Om Prakash Kumar (`@iamprakashom `_) +- Philipp Konrad (`@gardiac2002 `_) diff --git a/requests/models.py b/requests/models.py index db9df865..ba791721 100644 --- a/requests/models.py +++ b/requests/models.py @@ -436,7 +436,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): is_stream = all([ hasattr(data, '__iter__'), - not isinstance(data, (basestring, list, tuple, dict)) + not isinstance(data, (basestring, list, tuple, collections.Mapping)) ]) try: diff --git a/tests/test_requests.py b/tests/test_requests.py index f2d56b9e..5a2608e2 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -656,6 +656,31 @@ class TestRequests: with pytest.raises(ValueError): requests.post(url, files=['bad file data']) + def test_post_with_custom_mapping(self, httpbin): + class CustomMapping(collections.MutableMapping): + def __init__(self, *args, **kwargs): + self.data = dict(*args, **kwargs) + + def __delitem__(self, key): + del self.data[key] + + def __getitem__(self, key): + return self.data[key] + + def __setitem__(self, key, value): + self.data[key] = value + + def __iter__(self): + return iter(self.data) + + def __len__(self): + return len(self.data) + + data = CustomMapping({'some': 'data'}) + url = httpbin('post') + found_json = requests.post(url, data=data).json().get('form') + assert found_json == {'some': 'data'} + def test_conflicting_post_params(self, httpbin): url = httpbin('post') with open('requirements.txt') as f: