Merge pull request #1537 from Lukasa/datetime

Allow non-string objects to be posted as data alongside files.
This commit is contained in:
Kenneth Reitz
2013-08-21 11:46:27 -07:00
2 changed files with 12 additions and 0 deletions
+4
View File
@@ -106,6 +106,10 @@ class RequestEncodingMixin(object):
val = [val]
for v in val:
if v is not None:
# Don't call str() on bytestrings: in Py3 it all goes wrong.
if not isinstance(v, bytes):
v = str(v)
new_fields.append(
(field.decode('utf-8') if isinstance(field, bytes) else field,
v.encode('utf-8') if isinstance(v, str) else v))
+8
View File
@@ -663,6 +663,14 @@ class RequestsTestCase(unittest.TestCase):
self.assertTrue('unicode' in p.headers.keys())
self.assertTrue('byte' in p.headers.keys())
def test_can_send_nonstring_objects_with_files(self):
data = {'a': 0.0}
files = {'b': 'foo'}
r = requests.Request('POST', httpbin('post'), data=data, files=files)
p = r.prepare()
self.assertTrue('multipart/form-data' in p.headers['Content-Type'])
class TestCaseInsensitiveDict(unittest.TestCase):