Skip to content
Myr

Support responses like `HTTP/1.1 404 Unicode chars` (#3385)

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

authored by Andrii Kostenko · committed by Ian Cordasco · parent 71050e9 · Browse files · 2 files+15 added−2 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+15 added−2 removed

  • tests:+9 added−0 removed
  • other:+6 added−2 removed

2 files+15 added−2 removed

modified:requests/models.py+6 added-2 removed
847 unmodified lines
848 def raise_for_status(self):849 """Raises stored :class:`HTTPError`, if one occurred."""850851 http_error_msg = ''852 if isinstance(self.reason, bytes):853 reason = self.reason.decode('utf-8', 'ignore')854 else:855 reason = self.reason856857 if 400 <= self.status_code < 500:854 http_error_msg = '%s Client Error: %s for url: %s' % (self.status_code, self.reason, self.url)858 http_error_msg = u'%s Client Error: %s for url: %s' % (self.status_code, reason, self.url)859860 elif 500 <= self.status_code < 600:857 http_error_msg = '%s Server Error: %s for url: %s' % (self.status_code, self.reason, self.url)861 http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url)862863 if http_error_msg:864 raise HTTPError(http_error_msg, response=self)865
10 unmodified lines
modified:tests/test_requests.py+9 added
985 unmodified lines
986 r.encoding = None987 chunks = r.iter_content(decode_unicode=True)988 assert all(isinstance(chunk, str) for chunk in chunks)989990 def test_response_reason_unicode(self):991 # check for unicode HTTP status992 r = requests.Response()993 r.url = u'unicode URL'994 r.reason = u'Komponenttia ei löydy'.encode('utf-8')995 r.status_code = 404996 r.encoding = None997 assert not r.ok # old behaviour - crashes here998999 def test_response_chunk_size_type(self):1000 """Ensure that chunk_size is passed as None or an integer, otherwise1001 raise a TypeError.1002 """
771 unmodified lines