Replies: 9 comments
-
We've got a comment in the "requests compatibility" docs about this. |
Beta Was this translation helpful? Give feedback.
-
Link to aforementioned docs: https://www.python-httpx.org/compatibility#checking-for-4xx5xx-responses |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
See #809 I fail to see a use case were you would want to discard any errors (no logs, no treatment at all) and only perform action in case of successful response. This would be the only use case for a |
Beta Was this translation helpful? Give feedback.
-
I don't, I'm just a sassy opinionated coder |
Beta Was this translation helpful? Give feedback.
-
So you don't need to use import httpx
response = httpx.get()
if not response.is_error:
handle_success()
else:
handle_error() by: import httpx
response = httpx.get()
if response.is_error:
handle_error()
else:
handle_success() And then you have it, no negation involved :) |
Beta Was this translation helpful? Give feedback.
-
But then I'd be putting the (unlikely) error case before the (likely) success case! |
Beta Was this translation helpful? Give feedback.
-
Them's the breaks. |
Beta Was this translation helpful? Give feedback.
-
So, the reason we don't do this is pretty clear.
It's just not at all clear. (Incidentally, in requests it means the last one of those.) I could perhaps see us having response = httpx.get("https://www.example.com", allow_redirects=False)
if response.is_success:
... # Success condition
else:
... # Error condition Which doesn't do what it might look like it does on first sight. So... sure (I mean there's other options too. For instance, |
Beta Was this translation helpful? Give feedback.
-
resp.ok
is cuteBeta Was this translation helpful? Give feedback.
All reactions