-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
history
tuple on ClientResponseError empty with raise_for_status() or ClientSession(raise_for_status=True)
#3248
Comments
Or perhaps I am misunderstanding what |
Nice catch! Would you make a Pull Request for the fix? |
Problem: this doesn't appear isolated to the |
Perhaps this simply means that |
history
field on ClientResponseError missing with ClientSession(raise_for_status=True)history
field on ClientResponseError missing with raise_for_status() or ClientSession(raise_for_status=True)
history
field on ClientResponseError missing with raise_for_status() or ClientSession(raise_for_status=True)history
tuple on ClientResponseError empty with raise_for_status() or ClientSession(raise_for_status=True)
Got you. |
I'm looking for the |
Basically the equivalent of this in requests: import requests
try:
r = requests.get('http://httpbin.org/status/404')
r.raise_for_status()
except requests.exceptions.RequestException as e:
print(e.response.status_code)
print(e.response.text) which prints
(the response body is empty in this case, but imagine it wasn't) |
Consider response as closed after raising an exception. |
I understand the design rationale in general; I'm mainly observing that it makes most I wound up reading the response with If it were always possible to retrieve the Just throwing out ideas. 🙂 |
That's why you cannot rely on I understand your wish but sorry. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Long story short
When using a
ClientSession
created withraise_for_status=True
, the resultingClientResponseError
does not have itshistory
field populated, making it difficult to get the response data.Update: this is also true when calling
.raise_for_status()
explicitly.At a glance, it appears that
.raise_for_status()
is called before._history
is set on the response object:aiohttp/aiohttp/client.py
Lines 471 to 493 in 03d83b0
Expected behaviour
The
history
field should be a tuple ofClientResponse
objects.Actual behaviour
The
history
field is an empty tuple.Steps to reproduce
Your environment
The text was updated successfully, but these errors were encountered: