Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit empty reason strings in ClientResponse.raise_for_status() #3533

Merged
merged 2 commits into from
Jan 14, 2019
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
2 changes: 2 additions & 0 deletions CHANGES/3532.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raise a ClientResponseError instead of an AssertionError for a blank
HTTP Reason Phrase.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Joel Watts
Jon Nabozny
Joongi Kim
Josep Cugat
Joshu Coats
Julia Tsemusheva
Julien Duponchelle
Jungkook Park
Expand Down
3 changes: 2 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,8 @@ def release(self) -> Any:

def raise_for_status(self) -> None:
if 400 <= self.status:
assert self.reason # always not None for started response
# reason should always be not None for a started response
assert self.reason is not None
self.release()
raise ClientResponseError(
self.request_info,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_client_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,24 @@ def test_raise_for_status_4xx() -> None:
assert response.closed


def test_raise_for_status_4xx_without_reason() -> None:
response = ClientResponse('get', URL('http://def-cl-resp.org'),
request_info=mock.Mock(),
writer=mock.Mock(),
continue100=None,
timer=TimerNoop(),
traces=[],
loop=mock.Mock(),
session=mock.Mock())
response.status = 404
response.reason = ''
with pytest.raises(aiohttp.ClientResponseError) as cm:
response.raise_for_status()
assert str(cm.value.status) == '404'
assert str(cm.value.message) == ''
assert response.closed


def test_resp_host() -> None:
response = ClientResponse('get', URL('http://del-cl-resp.org'),
request_info=mock.Mock(),
Expand Down