Skip to content

Commit

Permalink
fix: allow requests to respect the environment
Browse files Browse the repository at this point in the history
Used for certs, for now.
  • Loading branch information
gadomski committed Apr 17, 2024
1 parent 4cd8f06 commit 7e08dff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pystac_client/stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions tests/test_stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/")

0 comments on commit 7e08dff

Please sign in to comment.