From: Denis Ryzhkov Date: Mon, 11 Feb 2013 12:37:58 +0000 (+0300) Subject: Fix of UnicodeDecodeError on unicode header name that can be converted to ascii. X-Git-Tag: v1.2.0~44^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6da7e22a4ab07f4b5a573d37a6149a2d5cfdb7af;p=services%2Fpython-requests.git Fix of UnicodeDecodeError on unicode header name that can be converted to ascii. --- diff --git a/AUTHORS.rst b/AUTHORS.rst index 078ed99..6bbddfd 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -120,3 +120,4 @@ Patches and Suggestions - David Bonner @rascalking - Vinod Chandru - Johnny Goodnow +- Denis Ryzhkov diff --git a/requests/models.py b/requests/models.py index a845b44..2ca5faa 100644 --- a/requests/models.py +++ b/requests/models.py @@ -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() diff --git a/test_requests.py b/test_requests.py index 6c4c3dd..e506ffa 100644 --- a/test_requests.py +++ b/test_requests.py @@ -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']))