Skip to content

Commit cd2be9c

Browse files
committed
Add retry on GET requests to QFieldCloud API
1 parent 12b5c62 commit cd2be9c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

qfieldcloud_sdk/sdk.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import requests
1010
import urllib3
11+
from requests.adapters import HTTPAdapter, Retry
1112

1213
from qfieldcloud_sdk.interfaces import QfcException, QfcRequest, QfcRequestException
1314
from qfieldcloud_sdk.utils import get_numeric_params, log
@@ -54,6 +55,16 @@ def __init__(
5455
`session` will be reused between requests if the SDK is run as a library.
5556
"""
5657
self.session = requests.Session()
58+
# retries should be only on GET and only if error 5xx
59+
retries = Retry(
60+
total=5,
61+
backoff_factor=0.1,
62+
allowed_methods=["GET"],
63+
# skip 501, as it is "Not Implemented", no point to retry
64+
status_forcelist=[500, 502, 503, 504],
65+
)
66+
self.session.mount("https://", HTTPAdapter(max_retries=retries))
67+
5768
self.url = url or os.environ.get("QFIELDCLOUD_URL", None)
5869
self.token = token or os.environ.get("QFIELDCLOUD_TOKEN", None)
5970
self.verify_ssl = verify_ssl

0 commit comments

Comments
 (0)