From 7e08dff6a90cefa13e91d03f69293d713df330a0 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 17 Apr 2024 07:21:36 -0600 Subject: [PATCH] fix: allow requests to respect the environment Used for certs, for now. --- CHANGELOG.md | 4 ++++ pystac_client/stac_api_io.py | 5 ++++- tests/test_stac_api_io.py | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec661e1..01a9daf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Use [uv](https://github.com/astral-sh/uv) for CI [#663](https://github.com/stac-utils/pystac-client/pull/663) - use `APILayoutStrategy` as fallback strategy [#666](https://github.com/stac-utils/pystac-client/pull/666) +### Fixed + +- Respect the `REQUESTS_CA_BUNDLE` and `CURL_CA_BUNDLE` environment variables when sending requests [#669](https://github.com/stac-utils/pystac-client/pull/669) + ## [v0.7.6] ### Fixed diff --git a/pystac_client/stac_api_io.py b/pystac_client/stac_api_io.py index e8f3bf73..9929395a 100644 --- a/pystac_client/stac_api_io.py +++ b/pystac_client/stac_api_io.py @@ -209,7 +209,10 @@ def request( if self.timeout is not None: msg += f" Timeout: {self.timeout}" logger.debug(msg) - resp = self.session.send(prepped, timeout=self.timeout) + send_kwargs = self.session.merge_environment_settings( + prepped.url, proxies={}, stream=None, verify=True, cert=None + ) + resp = self.session.send(prepped, timeout=self.timeout, **send_kwargs) except Exception as err: logger.debug(err) raise APIError(str(err)) diff --git a/tests/test_stac_api_io.py b/tests/test_stac_api_io.py index 11ff7fb6..bd1a4def 100644 --- a/tests/test_stac_api_io.py +++ b/tests/test_stac_api_io.py @@ -3,6 +3,7 @@ from urllib.parse import parse_qs, urlsplit import pytest +from pytest import MonkeyPatch from requests_mock.mocker import Mocker from pystac_client.exceptions import APIError @@ -266,3 +267,10 @@ def test_timeout_smoke_test(self) -> None: stac_api_io = StacApiIO(timeout=42) response = stac_api_io.read_text(STAC_URLS["PLANETARY-COMPUTER"]) assert isinstance(response, str) + + @pytest.mark.parametrize("name", ("REQUESTS_CA_BUNDLE", "CURL_CA_BUNDLE")) + def test_respect_env_for_certs(self, monkeypatch: MonkeyPatch, name: str) -> None: + monkeypatch.setenv(name, "/not/a/real/file") + stac_api_io = StacApiIO() + with pytest.raises(APIError): + stac_api_io.request("https://earth-search.aws.element84.com/v1/")