Skip to content

Commit be836af

Browse files
authored
Merge pull request #259 from dharmeshkakadia/client_specified_retry
Allow clients to control Retry specification
2 parents 0f54c9c + 9b3ad5e commit be836af

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

notion/client.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@
2727
from .utils import extract_id, now
2828

2929

30-
def create_session():
30+
def create_session(client_specified_retry=None):
3131
"""
3232
retry on 502
3333
"""
3434
session = Session()
35-
retry = Retry(
36-
5,
37-
backoff_factor=0.3,
38-
status_forcelist=(502,),
39-
# CAUTION: adding 'POST' to this list which is not technically idempotent
40-
method_whitelist=("POST", "HEAD", "TRACE", "GET", "PUT", "OPTIONS", "DELETE"),
41-
)
35+
if client_specified_retry:
36+
retry = client_specified_retry
37+
else:
38+
retry = Retry(
39+
5,
40+
backoff_factor=0.3,
41+
status_forcelist=(502,),
42+
# CAUTION: adding 'POST' to this list which is not technically idempotent
43+
method_whitelist=("POST", "HEAD", "TRACE", "GET", "PUT", "OPTIONS", "DELETE"),
44+
)
4245
adapter = HTTPAdapter(max_retries=retry)
4346
session.mount("https://", adapter)
4447
return session
@@ -58,8 +61,9 @@ def __init__(
5861
start_monitoring=False,
5962
enable_caching=False,
6063
cache_key=None,
64+
client_specified_retry=None,
6165
):
62-
self.session = create_session()
66+
self.session = create_session(client_specified_retry)
6367
self.session.cookies = cookiejar_from_dict({"token_v2": token_v2})
6468
if enable_caching:
6569
cache_key = cache_key or hashlib.sha256(token_v2.encode()).hexdigest()

0 commit comments

Comments
 (0)