You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AsyncClient raises a bare RuntimeError when middleware returns a sync-stream response #176
A middleware that short-circuits on an AsyncClient and returns a response built from a sync iterator makes the client raise a raw RuntimeError when it reads the body before decoding:
importasyncioimporthttpx2importhttpwareasyncdefshort_circuit(request: httpx2.Request, next: object) ->httpx2.Response:
returnhttpx2.Response(200, content=iter([b'{"a": 1}']), request=request)
asyncdefmain() ->None:
asyncwithhttpware.AsyncClient(base_url="http://x", middleware=[short_circuit]) asclient:
awaitclient.get("/", response_model=dict)
asyncio.run(main())
# RuntimeError: Attempted to call an async iterator on a sync stream.
The error comes from await response.aread() in AsyncClient before decoding. It is a programming error in the middleware, but it surfaces as a bare RuntimeError from inside httpx2 that doesn't point at the middleware. Options: raise a TypeError that names the problem, or accept a sync stream by reading it with read().
Activity