Skip to content
Myr

adding ISO-8859-1 fallback for reason decoding

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by Nate Prewitt · parent 58d855e · Browse files · 2 files+16 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−1 removed

  • tests:+12 added−0 removed
  • other:+4 added−1 removed

2 files+16 added−1 removed

modified:requests/models.py+4 added-1 removed
846 unmodified lines
847 """Raises stored :class:`HTTPError`, if one occurred."""848849 http_error_msg = ''850 if isinstance(self.reason, bytes):851 try:851 reason = self.reason.decode('utf-8', 'ignore')852 reason = self.reason.decode('utf-8')853 except UnicodeDecodeError:854 reason = self.reason.decode('iso-8859-1')855 else:856 reason = self.reason857858 if 400 <= self.status_code < 500:
20 unmodified lines
modified:tests/test_requests.py+12 added
1020 unmodified lines
1021 r.status_code = 4041022 r.encoding = None1023 assert not r.ok # old behaviour - crashes here10241025 def test_response_reason_unicode_fallback(self):1026 # check raise_status falls back to ISO-8859-11027 r = requests.Response()1028 r.url = 'some url'1029 reason = u'Komponenttia ei löydy'1030 r.reason = reason.encode('latin-1')1031 r.status_code = 5001032 r.encoding = None1033 with pytest.raises(requests.exceptions.HTTPError) as e:1034 r.raise_for_status()1035 assert reason in str(e)10361037 def test_response_chunk_size_type(self):1038 """Ensure that chunk_size is passed as None or an integer, otherwise1039 raise a TypeError.1040 """
796 unmodified lines