You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
It would be nice if the generated client could allow for retry hooks out of the box. For instance, currently when using requests we are able to hook into urllib3's retries to automatically retry certain failing status codes like temporary connection issues. Something like:
retries=Retry(
total=5,
method_whitelist=False, # the default whitelist excludes PATCH, False retries on all HTTP methodsbackoff_factor=0.5,
status_forcelist=[429,502,503,504]
)
adapter=HTTPAdapter(max_retries=retries)
session=requests.Session()
session.mount("http://", adapter)
session.mount("https://", adapter)
response=session.request("get", "http://example.com/")
Describe the solution you'd like
It would be great if we could somewhat similarly hook into the underlying retry mechanisms of httpx.
I would be OK exposing the direct hooks to HTTPX's retries, or introducing an abstraction in case the underlying HTTP library changed.
I imagine generated method signatures might look like:
Alternatively, as a superset of retry functionality we could perhaps expose a factory to create the httpx session itself since that's how it performs retries and might allow for further configuration.
It could also make sense to expose this at the Client level instead since I imagine most uses cases would be satisfied with a common configuration.
Describe alternatives you've considered
Without hooks into the direct HTTP client itself, the best approximation is to catch ApiResponseErrors and evaluate the response to attempt a manual retry.
So the httpx team seems to have been going back and forth on a retry API for some time. I think we should wait on adding our own retry functionality until they iron it out so we can take advantage of it. Latest issue tracking it is encode/httpx#1141 though this keeps changing.
It sure seems like they'll have it in place for 1.0 which they're moving pretty quickly toward.
Looks like this might be possible now via encode/httpcore#221 , but I don't see any clear documentation on how to do it. Anyone is free to give it a shot if they want. Also, it'll be easier to do manually (without inbuilt support here) once #202 is done.
Activity
dbanty commentedon Aug 27, 2020
So the httpx team seems to have been going back and forth on a retry API for some time. I think we should wait on adding our own retry functionality until they iron it out so we can take advantage of it. Latest issue tracking it is encode/httpx#1141 though this keeps changing.
It sure seems like they'll have it in place for 1.0 which they're moving pretty quickly toward.
bowenwr commentedon Aug 27, 2020
Thanks for the follow-up, I understand if
httpxis a moving target on retry functionality it's worth waiting on.dbanty commentedon Nov 14, 2020
Looks like this might be possible now via encode/httpcore#221 , but I don't see any clear documentation on how to do it. Anyone is free to give it a shot if they want. Also, it'll be easier to do manually (without inbuilt support here) once #202 is done.
tsotnikov commentedon May 21, 2021
I found in the documentation that retries (only connection retries) can be used via Custom Transports:
https://www.python-httpx.org/advanced/#custom-transports
Looking at the changelog, the minimum version to support this is
httpx >= 0.17.1