Fix of UnicodeDecodeError on unicode header name that can be converted to ascii.

This commit is contained in:
Denis Ryzhkov
2013-02-11 15:37:58 +03:00
parent 5d9fcc711b
commit 6da7e22a4a
3 changed files with 8 additions and 1 deletions
+1
View File
@@ -120,3 +120,4 @@ Patches and Suggestions
- David Bonner <dbonner@gmail.com> @rascalking
- Vinod Chandru
- Johnny Goodnow <j.goodnow29@gmail.com>
- Denis Ryzhkov <denisr@denisr.com>
+2
View File
@@ -325,6 +325,8 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
"""Prepares the given HTTP headers."""
if headers:
if is_py2:
headers = dict((builtin_str(name), value) for name, value in headers.items())
self.headers = CaseInsensitiveDict(headers)
else:
self.headers = CaseInsensitiveDict()
+5 -1
View File
@@ -10,7 +10,7 @@ import unittest
import requests
from requests.auth import HTTPDigestAuth
from requests.compat import str
from requests.compat import is_py2, str
try:
import StringIO
@@ -251,6 +251,10 @@ class RequestsTestCase(unittest.TestCase):
requests.get(url, params={'foo': 'foo'})
requests.get(httpbin('ø'), params={'foo': 'foo'})
def test_unicode_header_name(self):
if is_py2:
requests.put(httpbin('put'), headers={unicode('Content-Type'): 'application/octet-stream'}, data='\xff')
def test_urlencoded_get_query_multivalued_param(self):
r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))