Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pygeodes/_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.1.4"
version = "0.1.5"
name = "pygeodes"
description = "A Python client for Geodes APIs"
author = "CNES 2024"
54 changes: 46 additions & 8 deletions pygeodes/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
import requests
import validators
from requests.adapters import HTTPAdapter, Retry
from requests.exceptions import ReadTimeout
from requests.exceptions import ConnectionError
from requests.exceptions import Timeout
from requests.exceptions import HTTPError
from requests.exceptions import RequestException
from datetime import datetime
from tqdm import tqdm
from tqdm.asyncio import tqdm as tqdm_async

Expand Down Expand Up @@ -261,14 +267,46 @@ def post(

for attempt in range(MAX_NB_RETRIES):
begin = perf_counter()
response = self.session.post(
url,
headers=full_headers,
stream=True,
timeout=REQUESTS_TIMEOUT,
data=json.dumps(data),
verify=self.verify,
)
try:
response = self.session.post(
url,
headers=full_headers,
stream=True,
timeout=REQUESTS_TIMEOUT,
data=json.dumps(data),
verify=self.verify,
)
except ReadTimeout:
if attempt == MAX_NB_RETRIES - 1:
raise Exception("Request timed out after multiple retries")
logger.debug(f"{datetime.now()} : ReadTimeout occurred, retrying...")
time.sleep(TIME_BEFORE_RETRY)
continue
except ConnectionError:
if attempt == MAX_NB_RETRIES - 1:
raise Exception("Connection error: Could not connect to the server after multiple retries")
logger.debug(f"{datetime.now()} : Connection error, retrying...")
time.sleep(TIME_BEFORE_RETRY)
continue
except Timeout:
if attempt == MAX_NB_RETRIES - 1:
raise Exception("Request timeout occurred after multiple retries")
logger.debug(f"{datetime.now()} : Timeout occurred, retrying...")
time.sleep(TIME_BEFORE_RETRY)
continue
except RequestException as e:
if attempt == MAX_NB_RETRIES - 1:
raise Exception(f"Request failed: {str(e)} after multiple retries")
logger.debug("Request exception occurred, retrying...")
time.sleep(TIME_BEFORE_RETRY)
continue
except Exception as e:
if attempt == MAX_NB_RETRIES - 1:
raise Exception(f"Unexpected error: {str(e)} after multiple retries")
logger.debug("Unexpected error occurred, retrying...")
time.sleep(TIME_BEFORE_RETRY)
continue

end = perf_counter()
logger.debug(f"request made in {end-begin} seconds")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pygeodes"
version = "0.1.4"
version = "0.1.5"
description = "A Python client for Geodes APIs"
authors = ["CNES"]
readme = "README.md"
Expand Down