From 16c5a7a332f787d653f20a158061e5c357617230 Mon Sep 17 00:00:00 2001 From: Anton Burnashev Date: Fri, 16 Feb 2024 16:34:31 +0100 Subject: [PATCH] Receive a custom Session instance --- sources/rest_api/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sources/rest_api/client.py b/sources/rest_api/client.py index 07fec8617..6fb237445 100644 --- a/sources/rest_api/client.py +++ b/sources/rest_api/client.py @@ -2,9 +2,11 @@ import copy from requests.auth import AuthBase +from requests import Session as BaseSession + from dlt.common import logger -from dlt.sources.helpers import requests +from dlt.sources.helpers.requests import client from .paginators import BasePaginator, UnspecifiedPaginator from .detector import create_paginator @@ -29,10 +31,12 @@ def __init__( headers: Optional[Dict[str, str]] = None, auth: Optional[AuthBase] = None, paginator: Optional[BasePaginator] = None, + session: BaseSession = None ) -> None: self.base_url = base_url self.headers = headers self.auth = auth + self.session = session or client.session self.paginator = paginator if paginator else UnspecifiedPaginator() def make_request(self, path="", method="get", params=None, json=None): @@ -46,7 +50,7 @@ def make_request(self, path="", method="get", params=None, json=None): f"json={json}" ) - response = requests.request( + response = self.session.request( method=method, url=url, headers=self.headers,