Skip to content

httpx.ResponseNotRead: Attempted to access streaming response content, without having called read(). #1856

Discussion options

You must be logged in to vote

So... reading through the issue you raised against respx it looks to me that @lundberg has correctly identified what you need to change in your codebase, except that you can't change it in your endpoint handling (because the response is already closed by that point).

Instead you'd need to change your event hook, so that if it raises an exception, it reads the request body first...

async def hook(response: httpx.Response) -> None:
    if response.is_error:
        await response.aread()
        response.raise_for_status()

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@teror4uks
Comment options

@tomchristie
Comment options

@lundberg
Comment options

Answer selected by teror4uks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants