From 570c62b4bffcff8ea81b30ab5de9f55f42a4fb09 Mon Sep 17 00:00:00 2001 From: Dharani Prakash K M Date: Tue, 9 Jul 2024 07:04:59 +0530 Subject: [PATCH] Users/inkurdid/fix cert error (#609) * Use requests library instead of urllib * Update pyproject.toml * updated poetry.lock * Added types-requests for dev deps * Updated poetry.lock --- generated/nidaqmx/_install_daqmx.py | 16 +++++++++++----- poetry.lock | 24 +++++++++++++++++++----- pyproject.toml | 3 +++ src/handwritten/_install_daqmx.py | 16 +++++++++++----- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/generated/nidaqmx/_install_daqmx.py b/generated/nidaqmx/_install_daqmx.py index 5dcc2a9b..b8de6d3a 100644 --- a/generated/nidaqmx/_install_daqmx.py +++ b/generated/nidaqmx/_install_daqmx.py @@ -11,7 +11,7 @@ import sys import tempfile import traceback -import urllib.request +import requests import zipfile from typing import Generator, List, Optional, Tuple @@ -237,7 +237,10 @@ def _install_daqmx_driver_windows_core(download_url: str) -> None: try: with _multi_access_temp_file() as temp_file: _logger.info("Downloading Driver to %s", temp_file) - urllib.request.urlretrieve(download_url, temp_file) + response = requests.get(download_url) + response.raise_for_status() + with open(temp_file, 'wb') as f: + f.write(response.content) _logger.info("Installing NI-DAQmx") subprocess.run([temp_file], shell=True, check=True) except subprocess.CalledProcessError as e: @@ -245,7 +248,7 @@ def _install_daqmx_driver_windows_core(download_url: str) -> None: raise click.ClickException( f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'." ) from e - except urllib.error.URLError as e: + except requests.RequestException as e: _logger.info("Failed to download NI-DAQmx driver.", exc_info=True) raise click.ClickException(f"Failed to download the NI-DAQmx driver.\nDetails: {e}") from e except Exception as e: @@ -262,7 +265,10 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None: try: with _multi_access_temp_file(suffix=".zip") as temp_file: _logger.info("Downloading Driver to %s", temp_file) - urllib.request.urlretrieve(download_url, temp_file) + response = requests.get(download_url) + response.raise_for_status() + with open(temp_file, 'wb') as f: + f.write(response.content) with tempfile.TemporaryDirectory() as temp_folder: directory_to_extract_to = temp_folder @@ -292,7 +298,7 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None: raise click.ClickException( f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'." ) from e - except urllib.error.URLError as e: + except requests.RequestException as e: _logger.info("Failed to download NI-DAQmx driver.", exc_info=True) raise click.ClickException( f"Failed to download the NI-DAQmx driver.\nDetails: {e}" diff --git a/poetry.lock b/poetry.lock index a4494497..e3f5b452 100644 --- a/poetry.lock +++ b/poetry.lock @@ -139,7 +139,7 @@ files = [ name = "charset-normalizer" version = "3.3.2" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." -optional = true +optional = false python-versions = ">=3.7.0" files = [ {file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"}, @@ -840,7 +840,7 @@ files = [ name = "idna" version = "3.7" description = "Internationalized Domain Names in Applications (IDNA)" -optional = true +optional = false python-versions = ">=3.5" files = [ {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"}, @@ -1806,7 +1806,7 @@ files = [ name = "requests" version = "2.32.3" description = "Python HTTP for Humans." -optional = true +optional = false python-versions = ">=3.8" files = [ {file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"}, @@ -2077,6 +2077,20 @@ files = [ {file = "types_protobuf-4.25.0.20240417-py3-none-any.whl", hash = "sha256:e9b613227c2127e3d4881d75d93c93b4d6fd97b5f6a099a0b654a05351c8685d"}, ] +[[package]] +name = "types-requests" +version = "2.32.0.20240622" +description = "Typing stubs for requests" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-requests-2.32.0.20240622.tar.gz", hash = "sha256:ed5e8a412fcc39159d6319385c009d642845f250c63902718f605cd90faade31"}, + {file = "types_requests-2.32.0.20240622-py3-none-any.whl", hash = "sha256:97bac6b54b5bd4cf91d407e62f0932a74821bc2211f22116d9ee1dd643826caf"}, +] + +[package.dependencies] +urllib3 = ">=2" + [[package]] name = "typing-extensions" version = "4.12.2" @@ -2121,7 +2135,7 @@ devenv = ["check-manifest", "pytest (>=4.3)", "pytest-cov", "pytest-mock (>=3.3) name = "urllib3" version = "2.2.2" description = "HTTP library with thread-safe connection pooling, file post, and more." -optional = true +optional = false python-versions = ">=3.8" files = [ {file = "urllib3-2.2.2-py3-none-any.whl", hash = "sha256:a448b2f64d686155468037e1ace9f2d2199776e17f0a46610480d311f73e3472"}, @@ -2176,4 +2190,4 @@ grpc = ["grpcio", "protobuf"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "5a1f1b41e5a72a1fd846348094212e699901a982a63d811833952aa92ac21c96" +content-hash = "428e77bd486a39d56ff6c291a5f34bd24dd82d0ec105473d96a65af97d4b8e20" diff --git a/pyproject.toml b/pyproject.toml index 43fbde82..e63f32b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ tzlocal = "^5.0" python-decouple = ">=3.8" click = ">=8.0.0" distro = { version = ">=1.9.0", platform = "linux" } +requests = ">=2.25.0" [tool.poetry.extras] @@ -77,8 +78,10 @@ nptdms = ">=1.9.0" ni-python-styleguide = ">=0.4.1" mypy = ">=1.0" types-protobuf = "^4.21" +types-requests = ">=2.25.0" grpc-stubs = "^1.53" + [tool.poetry.group.test.dependencies] pytest = ">=7.2" pytest-cov = ">=4.0" diff --git a/src/handwritten/_install_daqmx.py b/src/handwritten/_install_daqmx.py index 5dcc2a9b..b8de6d3a 100644 --- a/src/handwritten/_install_daqmx.py +++ b/src/handwritten/_install_daqmx.py @@ -11,7 +11,7 @@ import sys import tempfile import traceback -import urllib.request +import requests import zipfile from typing import Generator, List, Optional, Tuple @@ -237,7 +237,10 @@ def _install_daqmx_driver_windows_core(download_url: str) -> None: try: with _multi_access_temp_file() as temp_file: _logger.info("Downloading Driver to %s", temp_file) - urllib.request.urlretrieve(download_url, temp_file) + response = requests.get(download_url) + response.raise_for_status() + with open(temp_file, 'wb') as f: + f.write(response.content) _logger.info("Installing NI-DAQmx") subprocess.run([temp_file], shell=True, check=True) except subprocess.CalledProcessError as e: @@ -245,7 +248,7 @@ def _install_daqmx_driver_windows_core(download_url: str) -> None: raise click.ClickException( f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'." ) from e - except urllib.error.URLError as e: + except requests.RequestException as e: _logger.info("Failed to download NI-DAQmx driver.", exc_info=True) raise click.ClickException(f"Failed to download the NI-DAQmx driver.\nDetails: {e}") from e except Exception as e: @@ -262,7 +265,10 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None: try: with _multi_access_temp_file(suffix=".zip") as temp_file: _logger.info("Downloading Driver to %s", temp_file) - urllib.request.urlretrieve(download_url, temp_file) + response = requests.get(download_url) + response.raise_for_status() + with open(temp_file, 'wb') as f: + f.write(response.content) with tempfile.TemporaryDirectory() as temp_folder: directory_to_extract_to = temp_folder @@ -292,7 +298,7 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None: raise click.ClickException( f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'." ) from e - except urllib.error.URLError as e: + except requests.RequestException as e: _logger.info("Failed to download NI-DAQmx driver.", exc_info=True) raise click.ClickException( f"Failed to download the NI-DAQmx driver.\nDetails: {e}"