Skip to content

Commit 570c62b

Browse files
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
1 parent 441569a commit 570c62b

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

generated/nidaqmx/_install_daqmx.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import tempfile
1313
import traceback
14-
import urllib.request
14+
import requests
1515
import zipfile
1616
from typing import Generator, List, Optional, Tuple
1717

@@ -237,15 +237,18 @@ def _install_daqmx_driver_windows_core(download_url: str) -> None:
237237
try:
238238
with _multi_access_temp_file() as temp_file:
239239
_logger.info("Downloading Driver to %s", temp_file)
240-
urllib.request.urlretrieve(download_url, temp_file)
240+
response = requests.get(download_url)
241+
response.raise_for_status()
242+
with open(temp_file, 'wb') as f:
243+
f.write(response.content)
241244
_logger.info("Installing NI-DAQmx")
242245
subprocess.run([temp_file], shell=True, check=True)
243246
except subprocess.CalledProcessError as e:
244247
_logger.info("Failed to install NI-DAQmx driver.", exc_info=True)
245248
raise click.ClickException(
246249
f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'."
247250
) from e
248-
except urllib.error.URLError as e:
251+
except requests.RequestException as e:
249252
_logger.info("Failed to download NI-DAQmx driver.", exc_info=True)
250253
raise click.ClickException(f"Failed to download the NI-DAQmx driver.\nDetails: {e}") from e
251254
except Exception as e:
@@ -262,7 +265,10 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None:
262265
try:
263266
with _multi_access_temp_file(suffix=".zip") as temp_file:
264267
_logger.info("Downloading Driver to %s", temp_file)
265-
urllib.request.urlretrieve(download_url, temp_file)
268+
response = requests.get(download_url)
269+
response.raise_for_status()
270+
with open(temp_file, 'wb') as f:
271+
f.write(response.content)
266272

267273
with tempfile.TemporaryDirectory() as temp_folder:
268274
directory_to_extract_to = temp_folder
@@ -292,7 +298,7 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None:
292298
raise click.ClickException(
293299
f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'."
294300
) from e
295-
except urllib.error.URLError as e:
301+
except requests.RequestException as e:
296302
_logger.info("Failed to download NI-DAQmx driver.", exc_info=True)
297303
raise click.ClickException(
298304
f"Failed to download the NI-DAQmx driver.\nDetails: {e}"

poetry.lock

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ tzlocal = "^5.0"
5050
python-decouple = ">=3.8"
5151
click = ">=8.0.0"
5252
distro = { version = ">=1.9.0", platform = "linux" }
53+
requests = ">=2.25.0"
5354

5455

5556
[tool.poetry.extras]
@@ -77,8 +78,10 @@ nptdms = ">=1.9.0"
7778
ni-python-styleguide = ">=0.4.1"
7879
mypy = ">=1.0"
7980
types-protobuf = "^4.21"
81+
types-requests = ">=2.25.0"
8082
grpc-stubs = "^1.53"
8183

84+
8285
[tool.poetry.group.test.dependencies]
8386
pytest = ">=7.2"
8487
pytest-cov = ">=4.0"

src/handwritten/_install_daqmx.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import tempfile
1313
import traceback
14-
import urllib.request
14+
import requests
1515
import zipfile
1616
from typing import Generator, List, Optional, Tuple
1717

@@ -237,15 +237,18 @@ def _install_daqmx_driver_windows_core(download_url: str) -> None:
237237
try:
238238
with _multi_access_temp_file() as temp_file:
239239
_logger.info("Downloading Driver to %s", temp_file)
240-
urllib.request.urlretrieve(download_url, temp_file)
240+
response = requests.get(download_url)
241+
response.raise_for_status()
242+
with open(temp_file, 'wb') as f:
243+
f.write(response.content)
241244
_logger.info("Installing NI-DAQmx")
242245
subprocess.run([temp_file], shell=True, check=True)
243246
except subprocess.CalledProcessError as e:
244247
_logger.info("Failed to install NI-DAQmx driver.", exc_info=True)
245248
raise click.ClickException(
246249
f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'."
247250
) from e
248-
except urllib.error.URLError as e:
251+
except requests.RequestException as e:
249252
_logger.info("Failed to download NI-DAQmx driver.", exc_info=True)
250253
raise click.ClickException(f"Failed to download the NI-DAQmx driver.\nDetails: {e}") from e
251254
except Exception as e:
@@ -262,7 +265,10 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None:
262265
try:
263266
with _multi_access_temp_file(suffix=".zip") as temp_file:
264267
_logger.info("Downloading Driver to %s", temp_file)
265-
urllib.request.urlretrieve(download_url, temp_file)
268+
response = requests.get(download_url)
269+
response.raise_for_status()
270+
with open(temp_file, 'wb') as f:
271+
f.write(response.content)
266272

267273
with tempfile.TemporaryDirectory() as temp_folder:
268274
directory_to_extract_to = temp_folder
@@ -292,7 +298,7 @@ def _install_daqmx_driver_linux_core(download_url: str, release: str) -> None:
292298
raise click.ClickException(
293299
f"An error occurred while installing the NI-DAQmx driver. Command returned non-zero exit status '{e.returncode}'."
294300
) from e
295-
except urllib.error.URLError as e:
301+
except requests.RequestException as e:
296302
_logger.info("Failed to download NI-DAQmx driver.", exc_info=True)
297303
raise click.ClickException(
298304
f"Failed to download the NI-DAQmx driver.\nDetails: {e}"

0 commit comments

Comments
 (0)