Limiting the number of retries is a way of increasing your applications performance. This lesson shows you how to do that by implementing a custom HTTP adapter. If you don’t know about adapters: don’t worry! You’ll learn about them in this lesson, too.
This allows a set of custom configurations per service, and we can set up a parameter for a maximum number of retries. As long as we’re in that
Session and that transport adapter is mounted, it will use those parameters and in this case, do the multiple retries.
Let’s check it out. Okay. Let’s create a new file. We’ll call it
max_retries.py. For it, we’ll import
requests, and then from
requests.adapters we’ll import the
HTTPAdapter, and then we’ll import an exception that would check for a
We’re going to use the
github_adapter for all requests to endpoints that start with this URL. So do that, we’ll do
session, and then we need to mount that adapter for this URL. A
We resave and retry, and it looks like we had no issues. The main purpose of showing this is to show how a Transport Adapter works and how it applies to a specific URL and how to mount it to a
Become a Member to join the conversation.