[add] Updated example with retries on 5xx errors
This commit is contained in:
parent
978c0ecd19
commit
7d9efbbe7d
11
example.py
11
example.py
@ -1,6 +1,13 @@
|
|||||||
import requests
|
import requests
|
||||||
|
from requests.adapters import HTTPAdapter, Retry
|
||||||
|
|
||||||
proxies = {'https': 'http://localhost:8080', 'http': 'http://localhost:8080'}
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user