diff --git a/requests/models.py b/requests/models.py index 9c624d3c..4bcbc548 100644 --- a/requests/models.py +++ b/requests/models.py @@ -81,7 +81,7 @@ class RequestEncodingMixin(object): """ if isinstance(data, (str, bytes)): - return to_native_string(data) + return data elif hasattr(data, 'read'): return data elif hasattr(data, '__iter__'): @@ -385,6 +385,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): if isinstance(fragment, str): fragment = fragment.encode('utf-8') + if isinstance(params, (str, bytes)): + params = to_native_string(params) + enc_params = self._encode_params(params) if enc_params: if query: diff --git a/test_requests.py b/test_requests.py index 137edc08..07952418 100755 --- a/test_requests.py +++ b/test_requests.py @@ -157,6 +157,11 @@ class TestRequests(object): params=b'test=foo').prepare() assert request.url == 'http://example.com/?test=foo' + def test_binary_put(self): + request = requests.Request('PUT', 'http://example.com', + data=u"ööö".encode("utf-8")).prepare() + assert isinstance(request.body, bytes) + def test_mixed_case_scheme_acceptable(self, httpbin): s = requests.Session() s.proxies = getproxies()