From 7d9efbbe7d43b6898e548d940e959fb844dc0020 Mon Sep 17 00:00:00 2001 From: Pablo Aramburo Date: Sat, 17 Sep 2022 20:06:45 -0600 Subject: [PATCH] [add] Updated example with retries on 5xx errors --- example.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/example.py b/example.py index c583cab..8928413 100644 --- a/example.py +++ b/example.py @@ -1,6 +1,13 @@ import requests +from requests.adapters import HTTPAdapter, Retry proxies = {'https': 'http://localhost:8080', 'http': 'http://localhost:8080'} -ip = requests.get(url='http://canhasip.com/', proxies=proxies).text -print(ip) +s = requests.Session() +retries = Retry(total=5, backoff_factor=1, status_forcelist=[ 502, 503, 504 ]) +s.mount('http://', HTTPAdapter(max_retries=retries)) +s.proxies = proxies + +ip = s.get('http://canhasip.com/') + +print(ip.text)