Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions notion/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@
from .utils import extract_id, now


def create_session():
def create_session(client_specified_retry=None):
"""
retry on 502
"""
session = Session()
retry = Retry(
5,
backoff_factor=0.3,
status_forcelist=(502,),
# CAUTION: adding 'POST' to this list which is not technically idempotent
method_whitelist=("POST", "HEAD", "TRACE", "GET", "PUT", "OPTIONS", "DELETE"),
)
if client_specified_retry:
retry = client_specified_retry
else:
retry = Retry(
5,
backoff_factor=0.3,
status_forcelist=(502,),
# CAUTION: adding 'POST' to this list which is not technically idempotent
method_whitelist=("POST", "HEAD", "TRACE", "GET", "PUT", "OPTIONS", "DELETE"),
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("https://", adapter)
return session
Expand All @@ -58,8 +61,9 @@ def __init__(
start_monitoring=False,
enable_caching=False,
cache_key=None,
client_specified_retry=None,
):
self.session = create_session()
self.session = create_session(client_specified_retry)
self.session.cookies = cookiejar_from_dict({"token_v2": token_v2})
if enable_caching:
cache_key = cache_key or hashlib.sha256(token_v2.encode()).hexdigest()
Expand Down