Skip to content
Myr

Add an Example for automatic retries to the Advanced Usage docs (#6258)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- While Requests doesn't automatically retry failures, this ability is a very common advanced use case in real world applications. - Although there's a mention of this ability on the HTTPAdapter class docs, it's a bit buried and not very specific. - It makes sense then to have an Example in the HTTPAdapter section of the Advanced Usage docs with a basic template for how this can be accomplished with Requests.

authored by Matthew Armand · committed by GitHub · parent 22db55a · Browse files · 1 file+22 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+22 added−0 removed

  • other:+22 added−0 removed

1 file+22 added−0 removed

modified:docs/user/advanced.rst+22 added
1024 unmodified lines
1025 self.poolmanager = PoolManager(1026 num_pools=connections, maxsize=maxsize,1027 block=block, ssl_version=ssl.PROTOCOL_SSLv3)10281029Example: Automatic Retries1030^^^^^^^^^^^^^^^^^^^^^^^^^^10311032By default, Requests does not retry failed connections. However, it is possible1033to implement automatic retries with a powerful array of features, including1034backoff, within a Requests :class:`Session <requests.Session>` using the1035`urllib3.util.Retry`_ class::10361037 from urllib3.util import Retry1038 from requests import Session1039 from requests.adapters import HTTPAdapter10401041 s = Session()1042 retries = Retry(1043 total=3,1044 backoff_factor=0.1,1045 status_forcelist=[502, 503, 504],1046 allowed_methods={'POST'},1047 )1048 s.mount('https://', HTTPAdapter(max_retries=retries))10491050.. _`described here`: https://kenreitz.org/essays/2012/06/14/the-future-of-python-http1051.. _`urllib3`: https://github.com/urllib3/urllib31052.. _`urllib3.util.Retry`: https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html#urllib3.util.Retry10531054.. _blocking-or-nonblocking:10551056Blocking Or Non-Blocking?
65 unmodified lines