Replies: 9 comments
|
We've got a comment in the "requests compatibility" docs about this. |
|
Link to aforementioned docs: https://www.python-httpx.org/compatibility#checking-for-4xx5xx-responses |
|
|
|
See https://github.com/encode/httpx/issues/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 |
I don't, I'm just a sassy opinionated coder |
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 :) |
But then I'd be putting the (unlikely) error case before the (likely) success case! |
Them's the breaks. |
|
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 conditionWhich doesn't do what it might look like it does on first sight. So... sure (I mean there's other options too. For instance, |
Uh oh!
There was an error while loading. Please reload this page.
resp.okis cuteAll reactions