From 937dd3559dd8147ac101d8a9a4cc78d822eef2cd Mon Sep 17 00:00:00 2001 From: T0jan Date: Wed, 28 Jun 2023 17:00:00 +0200 Subject: [PATCH] more errorhandling --- kintree/common/tools.py | 8 +++++--- run_tests.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kintree/common/tools.py b/kintree/common/tools.py index 603831ef..363fae8d 100644 --- a/kintree/common/tools.py +++ b/kintree/common/tools.py @@ -65,6 +65,7 @@ def download(url, filetype='API data', fileoutput='', timeout=3, enable_headers= import socket import urllib.request + import requests # Set default timeout for download socket socket.setdefaulttimeout(timeout) @@ -76,7 +77,6 @@ def download(url, filetype='API data', fileoutput='', timeout=3, enable_headers= if filetype == 'Image' or filetype == 'PDF': # Enable use of requests library for downloading files (some URLs do NOT work with urllib) if requests_lib: - import requests headers = {'User-agent': 'Mozilla/5.0'} response = requests.get(url, headers=headers, timeout=timeout, allow_redirects=True) if filetype.lower() not in response.headers['Content-Type'].lower(): @@ -95,12 +95,14 @@ def download(url, filetype='API data', fileoutput='', timeout=3, enable_headers= data = url_data.read() data_json = json.loads(data.decode('utf-8')) return data_json - except socket.timeout: + except (socket.timeout, requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout): cprint(f'[INFO]\tWarning: {filetype} download socket timed out ({timeout}s)', silent=silent) - except urllib.error.HTTPError: + except (urllib.error.HTTPError, requests.exceptions.ConnectionError): cprint(f'[INFO]\tWarning: {filetype} download failed (HTTP Error)', silent=silent) except (urllib.error.URLError, ValueError): cprint(f'[INFO]\tWarning: {filetype} download failed (URL Error)', silent=silent) + except requests.exceptions.SSLError: + cprint(f'[INFO]\tWarning: {filetype} download failed (SSL Error)', silent=silent) except FileNotFoundError: cprint(f'[INFO]\tWarning: {os.path.dirname(fileoutput)} folder does not exist', silent=silent) return None diff --git a/run_tests.py b/run_tests.py index afd420a7..17b08dac 100644 --- a/run_tests.py +++ b/run_tests.py @@ -424,6 +424,7 @@ def check_result(status: str, new_part: bool) -> bool: password='admin', enable_proxy=False, proxies={}, + datasheet_upload=True, user_config_path=settings.INVENTREE_CONFIG, ): method_success = False