Skip to content

Commit

Permalink
Merge pull request #348 from openvinotoolkit/address-bandit-issues
Browse files Browse the repository at this point in the history
CVS-117852 Fix bandit issues
  • Loading branch information
ljcornel authored Mar 5, 2024
2 parents 143b77a + 4802aa0 commit ab5c476
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion geti_sdk/demos/data_helpers/anomaly_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_mvtec_dataset_from_path(dataset_path: str = "data") -> str:

logging.info(f"Extracting the '{dataset_name}' dataset at path {archive_path}...")
with tarfile.open(archive_path) as tar_file:
tar_file.extractall(dataset_path)
tar_file.extractall(dataset_path) # nosec B202

if not is_ad_dataset(transistor_dataset_path):
raise ValueError(
Expand Down
11 changes: 8 additions & 3 deletions geti_sdk/demos/data_helpers/download_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def get_proxies(url: str = "", verify_cert: bool = True) -> Dict[str, str]:
"""
logging.info(f"Connecting to url {url}...")
proxies: Dict[str, str] = {}
timeout = 10
try:
requests.head(url=url, proxies=proxies, timeout=10, verify=verify_cert)
requests.head(url=url, proxies=proxies, timeout=timeout, verify=verify_cert)
return proxies
except requests.exceptions.ConnectionError:
logging.info("Unable to reach URL, attempting to connect via proxy...")
Expand All @@ -43,7 +44,7 @@ def get_proxies(url: str = "", verify_cert: bool = True) -> Dict[str, str]:
"https": "http://proxy-mu.intel.com:912",
}
try:
requests.head(url=url, proxies=proxies, verify=verify_cert)
requests.head(url=url, proxies=proxies, verify=verify_cert, timeout=timeout)
logging.info("Connection succeeded.")
except requests.exceptions.ConnectionError as error:
raise ValueError(
Expand All @@ -58,6 +59,7 @@ def download_file(
target_folder: Optional[str],
check_valid_archive: bool = False,
verify_cert: bool = True,
timeout: int = 1800,
) -> str:
"""
Download a file from `url` to a folder on local disk `target_folder`.
Expand All @@ -71,6 +73,7 @@ def download_file(
:param target_folder:
:param check_valid_archive: Check if the target file is a valid zip archive
:param verify_cert: False to disable SSL certificate validation
:param timeout: Time (in seconds) after which the download will time out
:return: path to the downloaded file
"""
filename = url.split("/")[-1]
Expand Down Expand Up @@ -99,7 +102,9 @@ def download_file(

proxies = get_proxies(url, verify_cert=verify_cert)
logging.info(f"Downloading {filename}...")
with requests.get(url, stream=True, proxies=proxies, verify=verify_cert) as r:
with requests.get(
url, stream=True, proxies=proxies, verify=verify_cert, timeout=timeout
) as r:
if r.status_code != 200:
r.raise_for_status()
raise RuntimeError(
Expand Down

0 comments on commit ab5c476

Please sign in to comment.