You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ClientResponse.raise_for_status() raises an AssertionError for a >= 400 status code if its reason is an empty string.
Expected behaviour
I expect ClientResponse.raise_for_status() to raise a ClientResponseError if it’s invoked on a ClientResponse with a status >= 400, and to either:
raise a ClientError (or some subclass of ClientError) if it’s called on a ClientResponse with a reason = None, regardless of the HTTP status code, if this can only happen when raise_for_status() has been called before start() has been called; or
convert a ClientResponse.reason of None into "" if None is a valid value for ClientResponse.reason
Actual behaviour
ClientResponse.raise_for_status() raises an AssertionError if it’s invoked on a ClientResponse when a status >= 400 and bool(reason) is False, which includes reason == ""
ClientResponse.raise_for_status() raises a ClientResponseError if it’s invoked on a ClientResponse with a status >= 400 if the reason is not falsey
ClientResponse.raise_for_status() raises no error if it’s invoked on a ClientResponse with a status < 400 and a reason = None
GitMate.io thinks the contributor most likely able to help you is @asvetlov.
Possibly related issues are #1177 (Static handler raises AssertionError), #156 (ClientResponse.content.read() raises ConnectionResetError), #1670 (ClientResponse ergonomics), #3248 (history tuple on ClientResponseError empty with raise_for_status() or ClientSession(raise_for_status=True)), and #1633 (Testing with pytest-aiohttp test_client raises an AssertionError.).
Long story short
ClientResponse.raise_for_status()
raises anAssertionError
for a >= 400 status code if itsreason
is an empty string.Expected behaviour
I expect
ClientResponse.raise_for_status()
to raise aClientResponseError
if it’s invoked on aClientResponse
with a status >= 400, and to either:ClientError
(or some subclass ofClientError
) if it’s called on aClientResponse
with areason = None
, regardless of the HTTP status code, if this can only happen whenraise_for_status()
has been called beforestart()
has been called; orClientResponse.reason
ofNone
into""
ifNone
is a valid value forClientResponse.reason
Actual behaviour
ClientResponse.raise_for_status()
raises an AssertionError if it’s invoked on aClientResponse
when a status >= 400 andbool(reason)
isFalse
, which includesreason == ""
ClientResponse.raise_for_status()
raises a ClientResponseError if it’s invoked on aClientResponse
with a status >= 400 if thereason
is not falseyClientResponse.raise_for_status()
raises no error if it’s invoked on aClientResponse
with a status < 400 and areason = None
Steps to reproduce
A colleague and I uncovered this using aioresponses, which currently doesn’t set a
reason
on theClientResponse
at all – see pnuckowski/aioresponses#114.You can reproduce this with the example client and server in this gist: https://gist.github.com/rhwlo/5ff3cb6bae8deb6abb4a1e527ad9583e
Your environment
I’m using the latest
aiohttp
from the repository, but this problem shows up only inv3.5.0
and newer.The text was updated successfully, but these errors were encountered: