Skip to content

Commit c508106

Browse files
committed
black
1 parent e4b01c3 commit c508106

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

osc_sdk_python/requester.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,30 @@
55
from urllib3.util.retry import Retry
66

77
HTTP_CODE_RETRY = (400, 429, 500, 503)
8-
METHODS_RETRY = ('POST', 'GET')
8+
METHODS_RETRY = ("POST", "GET")
9+
910

1011
class Requester:
11-
def __init__(self, auth, endpoint, max_retries=0, backoff_factor=2, status_forcelist=HTTP_CODE_RETRY, allowed_methods=METHODS_RETRY):
12+
def __init__(
13+
self,
14+
auth,
15+
endpoint,
16+
max_retries=0,
17+
backoff_factor=2,
18+
backoff_jitter=2,
19+
status_forcelist=HTTP_CODE_RETRY,
20+
allowed_methods=METHODS_RETRY,
21+
):
1222
self.auth = auth
1323
self.endpoint = endpoint
1424
if max_retries > 0:
15-
retry = Retry(total=max_retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist, allowed_methods=allowed_methods)
25+
retry = Retry(
26+
total=max_retries,
27+
backoff_factor=backoff_factor,
28+
backoff_jitter=backoff_jitter,
29+
status_forcelist=status_forcelist,
30+
allowed_methods=allowed_methods,
31+
)
1632
self.adapter = HTTPAdapter(max_retries=retry)
1733
else:
1834
self.adapter = HTTPAdapter()
@@ -25,22 +41,28 @@ def send(self, uri, payload):
2541
headers = self.auth.forge_headers_signed(uri, payload)
2642

2743
if self.auth.x509_client_cert is not None:
28-
cert_file=self.auth.x509_client_cert
44+
cert_file = self.auth.x509_client_cert
2945
else:
30-
cert_file=None
46+
cert_file = None
3147
if self.auth.proxy:
3248
if self.auth.proxy.startswith("https"):
33-
proxy= { "https": self.auth.proxy }
49+
proxy = {"https": self.auth.proxy}
3450
else:
35-
proxy= { "http": self.auth.proxy }
51+
proxy = {"http": self.auth.proxy}
3652
else:
37-
proxy=None
53+
proxy = None
3854

3955
with Session() as session:
4056
session.mount("https://", self.adapter)
4157
session.mount("http://", self.adapter)
42-
response = session.post(self.endpoint, data=payload, headers=headers, verify=True,
43-
proxies=proxy, cert=cert_file)
58+
response = session.post(
59+
self.endpoint,
60+
data=payload,
61+
headers=headers,
62+
verify=True,
63+
proxies=proxy,
64+
cert=cert_file,
65+
)
4466
self.raise_for_status(response)
4567
return response.json()
4668

@@ -85,9 +107,7 @@ def raise_for_status(self, response):
85107
f"url = {response.url}"
86108
)
87109
else:
88-
http_error_msg = (
89-
f"{response.status_code} Client Error: {reason} for url: {response.url}"
90-
)
110+
http_error_msg = f"{response.status_code} Client Error: {reason} for url: {response.url}"
91111

92112
elif 500 <= response.status_code < 600:
93113
if error_code and request_id:
@@ -101,9 +121,7 @@ def raise_for_status(self, response):
101121
f"url = {response.url}"
102122
)
103123
else:
104-
http_error_msg = (
105-
f"{response.status_code} Server Error: {reason} for url: {response.url}"
106-
)
124+
http_error_msg = f"{response.status_code} Server Error: {reason} for url: {response.url}"
107125

108126
if http_error_msg:
109127
raise HTTPError(http_error_msg, response=response)

0 commit comments

Comments
 (0)