mirror of
https://github.com/kennethreitz/requests3.git
synced 2026-06-05 23:10:16 +00:00
Ensure Content-Length is a string.
This commit is contained in:
+2
-2
@@ -121,7 +121,7 @@ class RequestEncodingMixin(object):
|
||||
fp = StringIO(fp)
|
||||
if isinstance(fp, bytes):
|
||||
fp = BytesIO(fp)
|
||||
|
||||
|
||||
if ft:
|
||||
new_v = (fn, fp.read(), ft)
|
||||
else:
|
||||
@@ -346,7 +346,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
])
|
||||
|
||||
try:
|
||||
length = super_len(data)
|
||||
length = str(super_len(data))
|
||||
except (TypeError, AttributeError):
|
||||
length = False
|
||||
|
||||
|
||||
+11
-2
@@ -9,6 +9,12 @@ import unittest
|
||||
|
||||
import requests
|
||||
from requests.auth import HTTPDigestAuth
|
||||
from requests.compat import str
|
||||
|
||||
try:
|
||||
import StringIO
|
||||
except ImportError:
|
||||
import io as StringIO
|
||||
|
||||
HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/')
|
||||
|
||||
@@ -131,8 +137,6 @@ class RequestsTestCase(unittest.TestCase):
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self):
|
||||
|
||||
|
||||
auth = ('user', 'pass')
|
||||
url = httpbin('basic-auth', 'user', 'pass')
|
||||
|
||||
@@ -264,6 +268,11 @@ class RequestsTestCase(unittest.TestCase):
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertTrue(b"text/py-content-type" in r.request.body)
|
||||
|
||||
def test_content_length_is_string_for_file_objects(self):
|
||||
r = requests.Request(url='http://httpbin.org/post',
|
||||
data=StringIO.StringIO('abc')).prepare()
|
||||
self.assertTrue(type(r.headers['Content-Length']) == str)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user