Skip to content

Commit

Permalink
Users/inkurdid/fix cert error (#609)
Browse files Browse the repository at this point in the history
* Use requests library instead of urllib

* Update pyproject.toml

* updated poetry.lock

* Added types-requests for dev deps

* Updated poetry.lock
  • Loading branch information
dharaniprakashkm authored Jul 9, 2024
1 parent 441569a commit 570c62b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
16 changes: 11 additions & 5 deletions generated/nidaqmx/_install_daqmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import tempfile
import traceback
import urllib.request
import requests
import zipfile
from typing import Generator, List, Optional, Tuple

Expand Down Expand Up @@ -237,15 +237,18 @@ 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:
_logger.info("Failed to install NI-DAQmx driver.", exc_info=True)
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:
Expand All @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
24 changes: 19 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 11 additions & 5 deletions src/handwritten/_install_daqmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import tempfile
import traceback
import urllib.request
import requests
import zipfile
from typing import Generator, List, Optional, Tuple

Expand Down Expand Up @@ -237,15 +237,18 @@ 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:
_logger.info("Failed to install NI-DAQmx driver.", exc_info=True)
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:
Expand All @@ -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
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 570c62b

Please sign in to comment.