mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Raising ValueError's when we're passed inconsistent POST data and files dict.
This commit is contained in:
+4
-2
@@ -92,8 +92,10 @@ class RequestEncodingMixin(object):
|
||||
if parameters are supplied as a dict.
|
||||
|
||||
"""
|
||||
if (not files) or isinstance(data, basestring):
|
||||
return None
|
||||
if (not files):
|
||||
raise ValueError("Files must be provided.")
|
||||
elif isinstance(data, basestring):
|
||||
raise ValueError("Data must not be a string.")
|
||||
|
||||
new_fields = []
|
||||
fields = to_key_val_list(data or {})
|
||||
|
||||
@@ -357,6 +357,12 @@ class RequestsTestCase(unittest.TestCase):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
with open('requirements.txt') as f:
|
||||
try:
|
||||
requests.post(url, data='[{"some": "data"}]', files={'some': f})
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def test_request_ok_set(self):
|
||||
r = requests.get(httpbin('status', '404'))
|
||||
self.assertEqual(r.ok, False)
|
||||
|
||||
Reference in New Issue
Block a user