-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Reading response after raise_for_status is no longer possible #27757
Comments
An improved version of raise_for_status could look: class ClientResponseErrorJson(ClientResponseError):
"""Json version of client response."""
pass
async def raise_for_status(response):
"""Improved raise_for_status with data in message."""
if response.status >= 400:
if 'json' in response.headers.get('CONTENT-TYPE', ''):
message = await response.json()
exception = ClientResponseErrorJson(
response.request_info,
response.history,
status=response.status,
message=message,
headers=response.headers
)
else:
assert response.reason is not None
exception = ClientResponseError(
response.request_info,
response.history,
status=response.status,
message=response.reason,
headers=response.headers
)
response.release()
raise exception With a: except ClientResponseError:
_LOGGER.error("Request failed", exc_info=_LOGGER.isEnabledFor(logging.DEBUG)) You get complete data at debug level, just an error otherwise in log. |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
Still valid |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
Still valid |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
Home Assistant release with the issue:
Anything using a aiohttp version after Oct 26, 2018
Last working Home Assistant release (if known):
Unknown
Operating environment (Hass.io/Docker/Windows/etc.):
Any
Description of problem:
aiohttp will since aio-libs/aiohttp#3365 not support reading the body of a http response after raise_for_status. Trying to do so will trigger yet another exception about connection already being closed.
Code known to have issue:
https://github.com/home-assistant/home-assistant/blob/f184bf4d8506c47db0860c2497900c5c44c17233/homeassistant/components/google_assistant/__init__.py#L101
Traceback (if applicable):
Additional information:
The text was updated successfully, but these errors were encountered: