Skip to content

Commit 0347651

Browse files
authored
fix: allow requests to respect the environment (#669)
Used for certs, for now.
1 parent 4cd8f06 commit 0347651

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Use [uv](https://github.com/astral-sh/uv) for CI [#663](https://github.com/stac-utils/pystac-client/pull/663)
1414
- use `APILayoutStrategy` as fallback strategy [#666](https://github.com/stac-utils/pystac-client/pull/666)
1515

16+
### Fixed
17+
18+
- Respect the `REQUESTS_CA_BUNDLE` and `CURL_CA_BUNDLE` environment variables when sending requests [#669](https://github.com/stac-utils/pystac-client/pull/669)
19+
1620
## [v0.7.6]
1721

1822
### Fixed

pystac_client/stac_api_io.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ def request(
209209
if self.timeout is not None:
210210
msg += f" Timeout: {self.timeout}"
211211
logger.debug(msg)
212-
resp = self.session.send(prepped, timeout=self.timeout)
212+
send_kwargs = self.session.merge_environment_settings(
213+
prepped.url, proxies={}, stream=None, verify=True, cert=None
214+
)
215+
resp = self.session.send(prepped, timeout=self.timeout, **send_kwargs)
213216
except Exception as err:
214217
logger.debug(err)
215218
raise APIError(str(err))

tests/test_stac_api_io.py

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from urllib.parse import parse_qs, urlsplit
44

55
import pytest
6+
from pytest import MonkeyPatch
67
from requests_mock.mocker import Mocker
78

89
from pystac_client.exceptions import APIError
@@ -266,3 +267,10 @@ def test_timeout_smoke_test(self) -> None:
266267
stac_api_io = StacApiIO(timeout=42)
267268
response = stac_api_io.read_text(STAC_URLS["PLANETARY-COMPUTER"])
268269
assert isinstance(response, str)
270+
271+
@pytest.mark.parametrize("name", ("REQUESTS_CA_BUNDLE", "CURL_CA_BUNDLE"))
272+
def test_respect_env_for_certs(self, monkeypatch: MonkeyPatch, name: str) -> None:
273+
monkeypatch.setenv(name, "/not/a/real/file")
274+
stac_api_io = StacApiIO()
275+
with pytest.raises(APIError):
276+
stac_api_io.request("https://earth-search.aws.element84.com/v1/")

0 commit comments

Comments
 (0)