Best Practices for Implementing Python Requests Retry: How Do You Handle Failed Requests?

8 Replies, 1972 Views

Yo, I’ve been down this rabbit hole too. For python requests retry, I usually roll my own retry loop with a bit of randomness to avoid hammering the server.

Something like:
```python
import time
import random

max_retries = 5
for i in range(max_retries):
try:
response = requests.get(url, timeout=10)
break
except:
time.sleep(random.uniform(1, 3))
```

It’s not fancy, but it works. For edge cases, I just log the failures and move on.

Messages In This Thread



Users browsing this thread: 1 Guest(s)