From: Ian Cordasco Date: Wed, 1 Aug 2012 14:36:45 +0000 (-0400) Subject: Better handling of invalid files. X-Git-Tag: v0.13.7~3^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ff165a1e2b30d5568c058b11139038963b4f979;p=services%2Fpython-requests.git Better handling of invalid files. I stole the idea from _encode_params in all candor. --- diff --git a/requests/models.py b/requests/models.py index 379c26d..9bda749 100644 --- a/requests/models.py +++ b/requests/models.py @@ -342,8 +342,15 @@ class Request(object): try: fields = list(self.data.items()) except AttributeError: + dict(self.data) fields = list(self.data) + try: + dict(files) + except ValueError: + raise ValueError('Unable to encode lists with elements that ' + 'are not 2-tuples.') + if isinstance(files, dict): files = files.items() diff --git a/tests/test_requests.py b/tests/test_requests.py index 5521557..4e0d034 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -320,6 +320,11 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase): post4 = post(url, data='[{"some": "json"}]') self.assertEqual(post4.status_code, 200) + try: + post(url, files=['bad file data']) + except ValueError: + pass + def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self): for service in SERVICES: