-
-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request]: raise httpx exception instead of buildin ConnectionResetError and ConnectionError #349
Comments
Hi @trim21, I think we're going to need a bit more context to address this issue. :-)
Thanks! |
@florimondmanca Sorry, I submit this issue by accident and I'm still writting details. |
Thanks for updating the description. :) I'm not entirely sure on this myself, I'll ping @tomchristie on this one. |
Probably because we don't capture any |
I remember that Trio already wraps errors such as ConnectionResetError into its own exceptions, eg BrokenResourceError. That means whatever wrapping we do needs to occur at the concurrency backend level. :) |
@florimondmanca I'm sorry, I'm not familiar with |
@trim21 HTTPX supports the async/await syntax, which under the hood requires us to work with a library able to perform asynchronous operations. Right now we only support asyncio (which is part of the standard library), but we’ve got plans for supporting alternatives such as trio - see #120. The « concurrency backend » I mentioned in my comment is an internal interface we use to abstract our code away from the individual async libraries. I guess the point in my comment was that which exceptions we need to wrap may depend on the async library in use, so we should do the wrapping at the concurrency backend level — provided we do want to wrap those exceptions. |
@florimondmanca thanks for your explanation |
will this be a feature of 1.0 ? |
It'll probably be in before 1.0, just requires a contributor to do the work! :) |
Yeah our guidelines here are probably roughly that all networking exception types should tend to be wrapped up in an HTTPX exception, although we're likely not at that point yet in several areas. |
Hope your Hacktoberfest is going well. Can confirm this happens with all connection types. All I need to do is turn off WiFi to replicate with both sync: >>> import httpx
>>> # With connection
>>> httpx.get("http://httpbin.org/status/200").status_code
200
>>> # Without connection
>>> httpx.get("http://httpbin.org/status/200").status_code
Traceback (most recent call last):
...
socket.gaierror: [Errno 8] nodename nor servname provided, or not known And async: >>> import asyncio
>>> import httpx
>>> async def fetch():
... async with httpx.AsyncClient() as client:
... return await client.get("http://httpbin.com/status/200")
...
>>> # With connection
>>> asyncio.run(fetch()).status_code
200
>>> # Without connection
>>> asyncio.run(fetch()).status_code
Traceback (most recent call last):
...
socket.gaierror: [Errno 8] nodename nor servname provided, or not known |
@flyinactor91 httpbin.com isn't a website. Do you mean https://httpbin.org? |
@sethmlarson He wants |
Lol. Yes I do. So much for typing things in again :) I'm currently handling generic connection issues via |
Did a bit of digging, and here's a list of cases it seems we'd want to wrap as HTTPX exceptions:
Note: asyncio doesn't seem to have network-related exceptions that we should handle -- see asyncio exceptions. (There's |
@florimondmanca Fantastic, thanks! It might be good to also cross-reference against exactly what exception heirarchy/wrapping users get with urllib3/requests. |
@tomchristie Sure! So it turns out to be a bit messy, but here's what I found…
|
The only tricky bit is streaming responses, because in that case we're doing I/O outside of Which means we may want to perform wrapping inside |
Really we want to wrap as close to the exception as possible. |
This is a feature requests instead of bug report.
I'm using
requests
in my web server to request upstream api. So I can handler allrequests.RequestException
in my middleware and return a502 upstream
error.But after I migrated to
httpx
, httpx doesn't have such exception when issuing a http(s) request, it will raisehttpx.ConnectTimeout
, buildinConnectionError
andConnectResetError
. And last 2 exception are not only raised byhttpx
.Maybe
httpx
should also wrapConnectionError
and other buildin connection exception?The text was updated successfully, but these errors were encountered: