How To Retry HTTP Requests Using a Decorator in Python

Published: 29 September 2021
on channel: John Watson Rooney
11,945
358

Failed requests to a server can cause us all sorts of issues, but rather than just handle the exception and log it away, retry it X amount of times using a retry decorator like this one.

I'll write and demo a retry decorator to show you how it works in principle, however if you are after something that is already written and perfected check out Retry-2 here: https://pypi.org/project/retry2/

the code in my example is here: https://github.com/jhnwr/retry-requests


Support Me:

Patreon:   / johnwatsonrooney   (NEW)
Amazon UK: https://amzn.to/2OYuMwo
Hosting: Digital Ocean: https://m.do.co/c/c7c90f161ff6
Gear Used: https://jhnwr.com/gear/ (NEW)

-------------------------------------
Disclaimer: These are affiliate links and as an Amazon Associate I earn from qualifying purchases
-------------------------------------