From a8ad0b06656b59f6951a9bc89513af1b4d32e665 Mon Sep 17 00:00:00 2001 From: meidlinga Date: Sat, 1 Oct 2022 18:48:10 +0200 Subject: [PATCH] feat: add option to skip tls cert verification An an option to skip certificate verification for downloads. When enabled, models can be downloaded from sites with invalid, expired, or self-signed TLS certificates. --- classify_images.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/classify_images.py b/classify_images.py index 5f57685..7deecf1 100644 --- a/classify_images.py +++ b/classify_images.py @@ -37,6 +37,7 @@ import glob import urllib import tempfile +import ssl # pip install progressbar2, not progressbar import progressbar @@ -93,6 +94,8 @@ # on the CPU or GPU. use_gpu = True +# Enable when downloads have invalid certificates and you want to risk trusting them +insecure_urllib = False #%% Constants @@ -176,7 +179,9 @@ def download_url(url, destination_filename=None, progress_updater=None, force_do print('Bypassing download of already-downloaded file {}'.format(os.path.basename(url))) return destination_filename print('Downloading file {}'.format(os.path.basename(url)),end='') - urllib.request.urlretrieve(url, destination_filename, progress_updater) + if (insecure_urllib): + ssl._create_default_https_context = ssl._create_unverified_context + urllib.request.urlretrieve(url, destination_filename, progress_updater) assert(os.path.isfile(destination_filename)) nBytes = os.path.getsize(destination_filename) print('...done, {} bytes.'.format(nBytes))