From 03964227c4968a818758a11a87240873dad25113 Mon Sep 17 00:00:00 2001 From: Anton Burnashev <anton.burnashev@gmail.com> Date: Sun, 9 Jun 2024 22:13:07 +0200 Subject: [PATCH] Pass environment settings to requests.Session.send, fixes #1447 --- dlt/sources/helpers/rest_client/client.py | 6 +++++- tests/sources/helpers/rest_client/test_client.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dlt/sources/helpers/rest_client/client.py b/dlt/sources/helpers/rest_client/client.py index 12db4310da..e6135b5c0f 100644 --- a/dlt/sources/helpers/rest_client/client.py +++ b/dlt/sources/helpers/rest_client/client.py @@ -124,7 +124,11 @@ def _send_request(self, request: Request) -> Response: prepared_request = self.session.prepare_request(request) - return self.session.send(prepared_request) + send_kwargs = self.session.merge_environment_settings( + prepared_request.url, {}, None, None, None + ) + + return self.session.send(prepared_request, **send_kwargs) def request(self, path: str = "", method: HTTPMethod = "GET", **kwargs: Any) -> Response: prepared_request = self._create_request( diff --git a/tests/sources/helpers/rest_client/test_client.py b/tests/sources/helpers/rest_client/test_client.py index 79a57d0e82..bd65affe62 100644 --- a/tests/sources/helpers/rest_client/test_client.py +++ b/tests/sources/helpers/rest_client/test_client.py @@ -241,3 +241,17 @@ def __call__(self, request: PreparedRequest) -> PreparedRequest: assert_pagination(pages_list) assert pages_list[0].response.request.headers["Authorization"] == "Bearer test-token" + + def test_send_request_allows_ca_bundle(self, mocker, rest_client): + mocker.patch.dict(os.environ, {"REQUESTS_CA_BUNDLE": "/path/to/some/ca-bundle"}) + + _send = rest_client.session.send + + def _fake_send(*args, **kwargs): + assert kwargs["verify"] == "/path/to/some/ca-bundle" + return _send(*args, **kwargs) + + rest_client.session.send = _fake_send + + result = rest_client.get("/posts/1") + assert result.status_code == 200