<p dir="auto">In requests 2.9.0:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; requests.patch('https://example.org', data=bytes('ô', 'utf-8'))
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/api.py&quot;, line 133, in patch
    return request('patch', url,  data=data, **kwargs)
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/api.py&quot;, line 53, in request
    return session.request(method=method, url=url, **kwargs)
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/sessions.py&quot;, line 454, in request
    prep = self.prepare_request(req)
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/sessions.py&quot;, line 388, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/models.py&quot;, line 296, in prepare
    self.prepare_body(data, files, json)
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/models.py&quot;, line 447, in prepare_body
    body = self._encode_params(data)
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/models.py&quot;, line 84, in _encode_params
    return to_native_string(data)
  File &quot;/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/utils.py&quot;, line 700, in to_native_string
    out = string.decode(encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; requests.patch('https://example.org', data=bytes('ô', 'utf-8'))
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/api.py", line 133, in patch
    return request('patch', url,  data=data, **kwargs)
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/api.py", line 53, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/sessions.py", line 454, in request
    prep = self.prepare_request(req)
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/sessions.py", line 388, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/models.py", line 296, in prepare
    self.prepare_body(data, files, json)
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/models.py", line 447, in prepare_body
    body = self._encode_params(data)
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/models.py", line 84, in _encode_params
    return to_native_string(data)
  File "/usr/local/combine/virtualenv/lib/python3.4/site-packages/requests/utils.py", line 700, in to_native_string
    out = string.decode(encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
</code></pre></div>
<p dir="auto">This seems to be a problem with all strings containing Unicode characters. It works without problems in 2.8.1.</p>
<p dir="auto">Hello,</p>
<p dir="auto">Our library suddenly stops to works in Python 3 for our users after <code class="notranslate">requests</code> 2.9 release, for instance:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="122400891" data-permission-text="Title is private" data-url="https://github.com/Azure/azure-storage-python/issues/89" data-hovercard-type="issue" data-hovercard-url="/Azure/azure-storage-python/issues/89/hovercard" href="https://github.com/Azure/azure-storage-python/issues/89">Azure/azure-storage-python#89</a></p>
<p dir="auto">I investigated the stack trace, and I found that when the body of the requests contains "real" bytes ("real" stands for OSImage, PDF,... not something readable), the code breaks.</p>
<p dir="auto">Especially, <code class="notranslate">requests</code> 2.9 in <code class="notranslate">requests.models#_encode_params</code> calls a new method <code class="notranslate">requests.utils#to_native_string</code> which tries to convert my bytes data using an ASCII encoder which is not possible if data are "real" bytes.</p>
<p dir="auto">This is the interesting part of the stacktrace extracting from the previously mentioned bug</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="self.response = self.session.request(self.method, self.uri, data=request_body, headers=self.headers, timeout=self.timeout)
  File &quot;/usr/local/lib/python3.5/site-packages/requests/sessions.py&quot;, line 454, in request
    prep = self.prepare_request(req)
  File &quot;/usr/local/lib/python3.5/site-packages/requests/sessions.py&quot;, line 388, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File &quot;/usr/local/lib/python3.5/site-packages/requests/models.py&quot;, line 296, in prepare
    self.prepare_body(data, files, json)
  File &quot;/usr/local/lib/python3.5/site-packages/requests/models.py&quot;, line 447, in prepare_body
    body = self._encode_params(data)
  File &quot;/usr/local/lib/python3.5/site-packages/requests/models.py&quot;, line 84, in _encode_params
    return to_native_string(data)
  File &quot;/usr/local/lib/python3.5/site-packages/requests/utils.py&quot;, line 700, in to_native_string
    out = string.decode(encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)"><pre class="notranslate"><code class="notranslate">self.response = self.session.request(self.method, self.uri, data=request_body, headers=self.headers, timeout=self.timeout)
  File "/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 454, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 388, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python3.5/site-packages/requests/models.py", line 296, in prepare
    self.prepare_body(data, files, json)
  File "/usr/local/lib/python3.5/site-packages/requests/models.py", line 447, in prepare_body
    body = self._encode_params(data)
  File "/usr/local/lib/python3.5/site-packages/requests/models.py", line 84, in _encode_params
    return to_native_string(data)
  File "/usr/local/lib/python3.5/site-packages/requests/utils.py", line 700, in to_native_string
    out = string.decode(encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
</code></pre></div>
<p dir="auto">What do you think? Tell me if I can help for anything.<br>
Thank you,</p>