Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,16 @@ def raise_for_status(self):
"""Raises stored :class:`HTTPError`, if one occurred."""

http_error_msg = ''
if isinstance(self.reason, bytes):
reason = self.reason.decode('utf-8', 'ignore')
else:
reason = self.reason

if 400 <= self.status_code < 500:
http_error_msg = '%s Client Error: %s for url: %s' % (self.status_code, self.reason, self.url)
http_error_msg = u'%s Client Error: %s for url: %s' % (self.status_code, reason, self.url)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did officially drop 3.2 support, right? I know we stopped running the tests, but we were supporting it regardless before this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dropped it like it was hot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sigmavirus24 I can add six.u for it.


elif 500 <= self.status_code < 600:
http_error_msg = '%s Server Error: %s for url: %s' % (self.status_code, self.reason, self.url)
http_error_msg = u'%s Server Error: %s for url: %s' % (self.status_code, reason, self.url)

if http_error_msg:
raise HTTPError(http_error_msg, response=self)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,15 @@ def test_response_decode_unicode(self):
chunks = r.iter_content(decode_unicode=True)
assert all(isinstance(chunk, str) for chunk in chunks)

def test_response_reason_unicode(self):
# check for unicode HTTP status
r = requests.Response()
r.url = u'unicode URL'
r.reason = u'Komponenttia ei löydy'.encode('utf-8')
r.status_code = 404
r.encoding = None
assert not r.ok # old behaviour - crashes here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still like this to be its own test, please. =)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lukasa done and updated PR


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to a new test, please?

def test_response_chunk_size_type(self):
"""Ensure that chunk_size is passed as None or an integer, otherwise
raise a TypeError.
Expand Down