| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | class KaggleDatasets: | |
| 7 | 7 | GET_GCS_PATH_ENDPOINT = '/requests/CopyDatasetVersionToKnownGcsBucketRequest' | |
| 8 | + TIMEOUT_SECS = 600 | ||
| 8 | 9 | ||
| 9 | 10 | # Integration types for GCS | |
| 10 | 11 | AUTO_ML = 1 | |
@@ -20,5 +21,5 @@ def get_gcs_path(self, dataset_dir: str = None) -> str: | |||
| 20 | 21 | 'MountSlug': dataset_dir, | |
| 21 | 22 | 'IntegrationType': integration_type, | |
| 22 | 23 | } | |
| 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) | ||
| 24 | 25 | return result['destinationBucket'] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,10 @@ | |||
| 9 | 9 | from enum import Enum, unique | |
| 10 | 10 | from typing import Optional, Tuple | |
| 11 | 11 | 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 | ||
| 13 | 16 | ||
| 14 | 17 | class NotFoundError(Exception): | |
| 15 | 18 | pass | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,11 +17,7 @@ class BackendError(Exception): | |||
| 17 | 17 | pass | |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | - class ValidationError(Exception): | ||
| 21 | - pass | ||
| 22 | - | ||
| 23 | 20 | class KaggleWebClient: | |
| 24 | - TIMEOUT_SECS = 600 | ||
| 25 | 21 | ||
| 26 | 22 | def __init__(self): | |
| 27 | 23 | url_base_override = os.getenv(_KAGGLE_URL_BASE_ENV_VAR_NAME) | |
@@ -38,14 +34,14 @@ def __init__(self): | |||
| 38 | 34 | 'X-Kaggle-Authorization': f'Bearer {self.jwt_token}', | |
| 39 | 35 | } | |
| 40 | 36 | ||
| 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: | ||
| 42 | 38 | url = f'{self.url_base}{endpoint}' | |
| 43 | 39 | request_body = dict(data) | |
| 44 | 40 | request_body['JWE'] = self.jwt_token | |
| 45 | 41 | req = urllib.request.Request(url, headers=self.headers, data=bytes( | |
| 46 | 42 | json.dumps(request_body), encoding="utf-8")) | |
| 47 | 43 | try: | |
| 48 | - with urllib.request.urlopen(req, timeout=self.TIMEOUT_SECS) as response: | ||
| 44 | + with urllib.request.urlopen(req, timeout=timeout) as response: | ||
| 49 | 45 | response_json = json.loads(response.read()) | |
| 50 | 46 | if not response_json.get('wasSuccessful') or 'result' not in response_json: | |
| 51 | 47 | raise BackendError( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | from kaggle_web_client import (KaggleWebClient, | |
| 10 | 10 | _KAGGLE_URL_BASE_ENV_VAR_NAME, | |
| 11 | 11 | _KAGGLE_USER_SECRETS_TOKEN_ENV_VAR_NAME, | |
| 12 | - CredentialError, BackendError, ValidationError) | ||
| 12 | + CredentialError, BackendError) | ||
| 13 | 13 | from kaggle_datasets import KaggleDatasets, _KAGGLE_TPU_NAME_ENV_VAR_NAME | |
| 14 | 14 | ||
| 15 | 15 | _TEST_JWT = 'test-secrets-key' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,10 @@ | |||
| 11 | 11 | from google.auth.exceptions import DefaultCredentialsError | |
| 12 | 12 | from google.cloud import bigquery | |
| 13 | 13 | from kaggle_secrets import (GcpTarget, UserSecretsClient, | |
| 14 | - NotFoundError) | ||
| 14 | + NotFoundError, ValidationError) | ||
| 15 | 15 | from kaggle_web_client import (_KAGGLE_URL_BASE_ENV_VAR_NAME, | |
| 16 | 16 | _KAGGLE_USER_SECRETS_TOKEN_ENV_VAR_NAME, | |
| 17 | - CredentialError, BackendError, ValidationError) | ||
| 17 | + CredentialError, BackendError) | ||
| 18 | 18 | ||
| 19 | 19 | _TEST_JWT = 'test-secrets-key' | |
| 20 | 20 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments