Better handling of invalid files.
authorIan Cordasco <graffatcolmingov@gmail.com>
Wed, 1 Aug 2012 14:36:45 +0000 (10:36 -0400)
committerIan Cordasco <graffatcolmingov@gmail.com>
Thu, 2 Aug 2012 21:31:30 +0000 (17:31 -0400)
I stole the idea from _encode_params in all candor.

requests/models.py
tests/test_requests.py

index 379c26d..9bda749 100644 (file)
@@ -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()
 
index 5521557..4e0d034 100755 (executable)
@@ -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: