ResponseNotRead when using raise_for_status hook #1973
Unanswered
nicklas-delphai
asked this question in
Potential Issue
Replies: 1 comment
-
|
Thanks Nicklas, that's useful feedback - might be worth us looking at if it's possible to improve on the user experience here one way or another. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In my setup I configure the
AsyncClientto callresponse.raise_for_status()for every call using theraise_on_4xx_5xxresponse hook as stated in the documentation.When catching
HTTPStatusErrorasexI was very confused to find thatex.response.json()would raiseResponseNotReadexception instead of giving me the expected json data.After doing some digging in the source code I realized two things:
This will mean that if a user uses the
raise_on_4xx_5xxas shown in the documentation they might unexpectedly run into the same issue as I did, whereread()has not been called yet.I believe this is very confusing. At least I can say it confused the hell out of me and cost me the better part of 2 hours now to figure out.
My solution to this problem was to extend the
raise_on_4xx_5xxhook:Also it's worth to note that I didn't need this workaround previous to v0.19. Before v0.19 everything worked as I would expect and I could call
ex.response.json()without encountering this exception.Edit
I probably should have read the note in the documentation:
That's on me. Anyway, I still find it pretty unpredictable.
Beta Was this translation helpful? Give feedback.
All reactions