From: Tyler Chamberlain Date: Mon, 1 Nov 2021 11:39:18 +0000 (-0500) Subject: Expand docs note for async custom handler responses (#1916) X-Git-Tag: 0.21.0~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da8f959af02e8d8dec69311ac8981fed90944573;p=thirdparty%2Fhttpx.git Expand docs note for async custom handler responses (#1916) * Expand note for async custom handler responses Custom response handlers need to run `response.read()` before they can read the content of the response. However when using an AsyncClient this will produce an error of `RuntimeError: Attempted to call a sync iterator on an async stream.`. Took me some digging to figure out I just needed to use `response.aread()` here instead of `response.read()` so figured I would an MR with an expansion on the note for anyone else. Thanks! * Update advanced.md --- diff --git a/docs/advanced.md b/docs/advanced.md index ea012bd9..54be4ae0 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -260,7 +260,7 @@ client = httpx.Client(event_hooks={'response': [raise_on_4xx_5xx]}) should be read or not. If you need access to the response body inside an event hook, you'll - need to call `response.read()`. + need to call `response.read()`, or for AsyncClients, `response.aread()`. The hooks are also allowed to modify `request` and `response` objects.