raise_for_status in event hooks raises exception for 301 even if follow_redirects flag is set to True #2008
Unanswered
cjcjcj
asked this question in
Potential Issue
Replies: 1 comment 1 reply
-
|
Okay, so the event hook is firing on all responses. That's including the intermediary redirects (and any auth flow responses). If you're using the event hooks to raise_for_status, then you'd need to do something like this I guess... def raise_4xx_5xx(response: httpx.Response):
if not response.is_redirect:
response.raise_for_status()I'm not sure how well our event hook behaviour is documented here. It's also occurred to me in the past that we might want |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Context: I've a lot of requests to one host which should normally return 200 code, if one of them returns 4xx or 5xx, I'm raising an error.
I decided to use event_hooks to reduce boilerplate of
raise_for_statususage(basically, I've copy pasted example from documentation).Using
httpx.Client(follow_redirects=True, event_hooks={"response": [raise_4xx_5xx]}), leads to an error when a redirect is encountered.Traceback
Here is the code to reproduce this behaviour:
client side code
server side code
Is it expected behaviour or issue candidate?
Beta Was this translation helpful? Give feedback.
All reactions