import os
import socket
from datetime import datetime
+from io import BytesIO
from .hooks import dispatch_hook, HOOKS
from .structures import CaseInsensitiveDict
else:
fn = guess_filename(v) or k
fp = v
- if isinstance(fp, (bytes, str)):
+ if isinstance(fp, str):
fp = StringIO(fp)
+ if isinstance(fp, bytes):
+ fp = BytesIO(fp)
fields.append((k, (fn, fp.read())))
for k, vs in tuples(self.data):
import sys
import os
sys.path.insert(0, os.path.abspath('..'))
-
import json
import os
import unittest
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__'),
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()