Skip to content
Snippets Groups Projects
Commit dd4b6617 authored by Manon Blanco's avatar Manon Blanco
Browse files

Add retry mechanism on image download

parent 8dad762d
No related branches found
No related tags found
1 merge request!409Add retry mechanism on image download
Pipeline #136968 passed
......@@ -91,7 +91,7 @@ def download_image(url: str) -> Image:
# Cannot use stream=True as urllib's responses do not support the seek(int) method,
# which is explicitly required by Image.open on file-like objects
try:
resp = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
resp = _retried_request(url)
except requests.exceptions.SSLError:
logger.warning(
"An SSLError occurred during image download, retrying with a weaker and unsafe SSL configuration"
......@@ -102,13 +102,11 @@ def download_image(url: str) -> Image:
# Downgrading ciphers to download the image
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = "ALL:@SECLEVEL=1"
resp = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
resp = _retried_request(url)
# Restoring previous ciphers
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = previous_ciphers
resp.raise_for_status()
# Preprocess the image and prepare it for classification
image = Image.open(BytesIO(resp.content))
logger.info(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment