Skip to content
Snippets Groups Projects
Commit 66f50605 authored by Eva Bardou's avatar Eva Bardou Committed by Bastien Abadie
Browse files

Support weak SSL DH key when downloading images

parent cd30de66
No related branches found
No related tags found
1 merge request!86Support weak SSL DH key when downloading images
Pipeline #78425 passed
......@@ -48,10 +48,27 @@ def download_image(url):
Download an image and open it with Pillow
"""
assert url.startswith("http"), "Image URL must be HTTP(S)"
# Download the 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
resp = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
try:
resp = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
except requests.exceptions.SSLError:
logger.warning(
"An SSLError occurred during image download, retrying with a weaker and unsafe SSL configuration"
)
# Saving current ciphers
previous_ciphers = requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS
# Downgrading ciphers to download the image
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = "ALL:@SECLEVEL=1"
resp = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
# Restoring previous ciphers
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = previous_ciphers
resp.raise_for_status()
# Preprocess the image and prepare it for classification
......
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