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

Reading response after raise_for_status is no longer possible #27757

Closed
elupus opened this issue Oct 16, 2019 · 6 comments
Closed

Reading response after raise_for_status is no longer possible #27757

elupus opened this issue Oct 16, 2019 · 6 comments
Labels

Comments

@elupus
Copy link
Contributor

elupus commented Oct 16, 2019

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:

@elupus
Copy link
Contributor Author

elupus commented Oct 27, 2019

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.

@stale
Copy link

stale bot commented Jan 25, 2020

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.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 25, 2020
@elupus
Copy link
Contributor Author

elupus commented Jan 26, 2020

Still valid

@stale stale bot removed the stale label Jan 26, 2020
@stale
Copy link

stale bot commented Apr 25, 2020

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.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 25, 2020
@elupus
Copy link
Contributor Author

elupus commented Apr 25, 2020

Still valid

@stale stale bot removed the stale label Apr 25, 2020
@stale
Copy link

stale bot commented Jul 25, 2020

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.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 25, 2020
@stale stale bot closed this as completed Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant