mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
adding ISO-8859-1 fallback for reason decoding
This commit is contained in:
+4
-1
@@ -848,7 +848,10 @@ class Response(object):
|
||||
|
||||
http_error_msg = ''
|
||||
if isinstance(self.reason, bytes):
|
||||
reason = self.reason.decode('utf-8', 'ignore')
|
||||
try:
|
||||
reason = self.reason.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
reason = self.reason.decode('iso-8859-1')
|
||||
else:
|
||||
reason = self.reason
|
||||
|
||||
|
||||
@@ -1022,6 +1022,18 @@ class TestRequests:
|
||||
r.encoding = None
|
||||
assert not r.ok # old behaviour - crashes here
|
||||
|
||||
def test_response_reason_unicode_fallback(self):
|
||||
# check raise_status falls back to ISO-8859-1
|
||||
r = requests.Response()
|
||||
r.url = 'some url'
|
||||
reason = u'Komponenttia ei löydy'
|
||||
r.reason = reason.encode('latin-1')
|
||||
r.status_code = 500
|
||||
r.encoding = None
|
||||
with pytest.raises(requests.exceptions.HTTPError) as e:
|
||||
r.raise_for_status()
|
||||
assert reason in str(e)
|
||||
|
||||
def test_response_chunk_size_type(self):
|
||||
"""Ensure that chunk_size is passed as None or an integer, otherwise
|
||||
raise a TypeError.
|
||||
|
||||
Reference in New Issue
Block a user