-
Notifications
You must be signed in to change notification settings - Fork 29
/
bridge.py
36 lines (31 loc) · 1.01 KB
/
bridge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
class Bridge(object):
def __init__(
self,
retries=3,
backoff_factor=0.3,
status_forcelist=(500, 502, 504),
):
self.session = requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
self.session.mount('http://', adapter)
self.session.mount('https://', adapter)
def request(self, url, params={}, headers={}, timeout=15):
try:
return self.session.get(url,
params=params,
headers=headers,
timeout=timeout)
except Exception as e:
raise e
def close(self):
self.session.close()