Skip to content

Commit 3bf1afa

Browse files
committed
Improve request timeout handling
1 parent 496ffa2 commit 3bf1afa

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Removed support for file system credentials caching.
44
* S3 download URLs are now validated.
5+
* Improved request timeout handling.
56

67
## 4.0.0 - 2026-01-22
78

okdata/sdk/auth/credentials/password_grant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ def refresh_token(self, refresh_token):
3535

3636
def new_token(self):
3737
payload = {"username": self.username, "password": self.password}
38-
response = requests.post(url=self.token_service_url, json=payload)
38+
response = requests.post(url=self.token_service_url, json=payload, timeout=10)
3939
return response.json()

okdata/sdk/data/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def download(self, dataset_id, version, edition, output_path, retries=0):
4141
if not file_url.startswith(base_url):
4242
raise DownloadURLAssertionError(file_url, base_url)
4343

44-
file_content_response = requests.get(file_url, stream=True)
44+
file_content_response = requests.get(file_url, stream=True, timeout=10)
4545
file_content_response.raise_for_status()
4646

4747
write_file_content(file_name, output_path, file_content_response.raw.read())

okdata/sdk/sdk.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
log = logging.getLogger()
1010

1111

12+
class TimeoutHTTPAdapter(HTTPAdapter):
13+
"""HTTP adapter with a default timeout."""
14+
15+
def send(self, request, *args, **kwargs):
16+
kwargs["timeout"] = 10 # Defualt timeout (seconds)
17+
return super().send(request, *args, **kwargs)
18+
19+
1220
class SDK:
1321
def __init__(self, config=None, auth=None, env=None):
1422
self.config = config
@@ -72,7 +80,7 @@ def prepared_request_with_retries(retries):
7280
"TRACE",
7381
],
7482
)
75-
adapter = HTTPAdapter(max_retries=retry_strategy)
83+
adapter = TimeoutHTTPAdapter(max_retries=retry_strategy)
7684
session = requests.Session()
7785
session.mount("https://", adapter)
7886
session.mount("http://", adapter)

0 commit comments

Comments
 (0)