Use BytesIO for bytes.

This fixes a TypeError on Python 3 that ocurred when passing
bytes as the values for files.
This commit is contained in:
Jakub Roztocil
2012-07-30 10:35:47 +02:00
parent cfa627ae62
commit dee3693ea0
2 changed files with 11 additions and 3 deletions
+7 -2
View File
@@ -7,7 +7,6 @@
import sys
import os
sys.path.insert(0, os.path.abspath('..'))
import json
import os
import unittest
@@ -1030,7 +1029,9 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
def test_post_fields_with_multiple_values_and_files_as_tuples(self):
"""Test that it is possible to POST multiple data and file fields
with the same name."""
with the same name.
https://github.com/kennethreitz/requests/pull/746
"""
data = [
('__field__', '__value__'),
@@ -1061,6 +1062,10 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
self.assertEqual(body.count('__value__'), 4)
self.assertEqual(body.count(file_field), 2)
def test_bytes_files(self):
"""Test that `bytes` can be used as the values of `files`."""
post(httpbin('post'), files={'test': b'test'})
if __name__ == '__main__':
unittest.main()