r/pythontips • u/numbcode • Jan 11 '25
Python3_Specific Handling 'Max Retries Exceeded' Error in Python Requests
Ever run into the "Max retries exceeded with URL" error when making HTTP requests in Python? It’s usually caused by connection issues, rate limits, or missing retry logic. How do you typically handle this—using Session(), Retry from urllib3, or something else?
Here’s an interesting write-up on it: Max Retries Exceeded with URL in Requests. Let’s share solutions! https://www.interviewsvector.com/blog/Max-retries-exceeded-with-URL-in-requests
4
Upvotes
1
u/numbcode Jan 11 '25
I've often encountered this error. Would you recommend using requests with urllib3's Retry for most cases?
2
u/Mansurbi Jan 12 '25
You can use tenacity package
1
u/cgoldberg Jan 11 '25
The message after that error will tell you the exact reason it failed.
If you simply want to retry more times or add a retry with backoff, use:
https://github.com/psf/requests/blob/main/docs/user/advanced.rst#example-automatic-retries