Skip to content

Commit 2259a07

Browse files
committed
Move timeout
1 parent 4e07647 commit 2259a07

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

patches/kaggle_datasets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class KaggleDatasets:
77
GET_GCS_PATH_ENDPOINT = '/requests/CopyDatasetVersionToKnownGcsBucketRequest'
8+
TIMEOUT_SECS = 600
89

910
# Integration types for GCS
1011
AUTO_ML = 1
@@ -20,5 +21,5 @@ def get_gcs_path(self, dataset_dir: str = None) -> str:
2021
'MountSlug': dataset_dir,
2122
'IntegrationType': integration_type,
2223
}
23-
result = self.web_client.make_post_request(data, self.GET_GCS_PATH_ENDPOINT)
24+
result = self.web_client.make_post_request(data, self.GET_GCS_PATH_ENDPOINT, self.TIMEOUT_SECS)
2425
return result['destinationBucket']

patches/kaggle_secrets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
from enum import Enum, unique
1010
from typing import Optional, Tuple
1111
from kaggle_web_client import KaggleWebClient
12-
from kaggle_web_client import (CredentialError, BackendError, ValidationError)
12+
from kaggle_web_client import (CredentialError, BackendError)
13+
14+
class ValidationError(Exception):
15+
pass
1316

1417
class NotFoundError(Exception):
1518
pass

patches/kaggle_web_client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ class BackendError(Exception):
1717
pass
1818

1919

20-
class ValidationError(Exception):
21-
pass
22-
2320
class KaggleWebClient:
24-
TIMEOUT_SECS = 600
2521

2622
def __init__(self):
2723
url_base_override = os.getenv(_KAGGLE_URL_BASE_ENV_VAR_NAME)
@@ -38,14 +34,14 @@ def __init__(self):
3834
'X-Kaggle-Authorization': f'Bearer {self.jwt_token}',
3935
}
4036

41-
def make_post_request(self, data: dict, endpoint: str) -> dict:
37+
def make_post_request(self, data: dict, endpoint: str, timeout: int = TIMEOUT_SECS) -> dict:
4238
url = f'{self.url_base}{endpoint}'
4339
request_body = dict(data)
4440
request_body['JWE'] = self.jwt_token
4541
req = urllib.request.Request(url, headers=self.headers, data=bytes(
4642
json.dumps(request_body), encoding="utf-8"))
4743
try:
48-
with urllib.request.urlopen(req, timeout=self.TIMEOUT_SECS) as response:
44+
with urllib.request.urlopen(req, timeout=timeout) as response:
4945
response_json = json.loads(response.read())
5046
if not response_json.get('wasSuccessful') or 'result' not in response_json:
5147
raise BackendError(

tests/test_datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from kaggle_web_client import (KaggleWebClient,
1010
_KAGGLE_URL_BASE_ENV_VAR_NAME,
1111
_KAGGLE_USER_SECRETS_TOKEN_ENV_VAR_NAME,
12-
CredentialError, BackendError, ValidationError)
12+
CredentialError, BackendError)
1313
from kaggle_datasets import KaggleDatasets, _KAGGLE_TPU_NAME_ENV_VAR_NAME
1414

1515
_TEST_JWT = 'test-secrets-key'

tests/test_user_secrets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from google.auth.exceptions import DefaultCredentialsError
1212
from google.cloud import bigquery
1313
from kaggle_secrets import (GcpTarget, UserSecretsClient,
14-
NotFoundError)
14+
NotFoundError, ValidationError)
1515
from kaggle_web_client import (_KAGGLE_URL_BASE_ENV_VAR_NAME,
1616
_KAGGLE_USER_SECRETS_TOKEN_ENV_VAR_NAME,
17-
CredentialError, BackendError, ValidationError)
17+
CredentialError, BackendError)
1818

1919
_TEST_JWT = 'test-secrets-key'
2020

0 commit comments

Comments
 (0)