Skip to content

Commit

Permalink
Use self.session for making a request in obtain_token
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash committed Jun 20, 2024
1 parent edfff5b commit 41fff55
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dlt/sources/helpers/rest_client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def __init__(
self.access_token_request_data = access_token_request_data
self.default_token_expiration = default_token_expiration
self.token_expiry: pendulum.DateTime = pendulum.now()
if session is None:
self.session = requests.client.session

self.session = session if session is not None else requests.client.session

def __call__(self, request: PreparedRequest) -> PreparedRequest:
if self.access_token is None or self.is_token_expired():
Expand All @@ -189,7 +189,7 @@ def is_token_expired(self) -> bool:
return pendulum.now() >= self.token_expiry

def obtain_token(self) -> None:
response = requests.post(self.access_token_url, **self.build_access_token_request())
response = self.session.post(self.access_token_url, **self.build_access_token_request())
response.raise_for_status()
response_json = response.json()
self.parse_native_representation(self.parse_access_token(response_json))
Expand All @@ -205,7 +205,7 @@ def build_access_token_request(self) -> Dict[str, Any]:
"client_id": self.client_id,
"client_secret": self.client_secret,
"grant_type": "client_credentials",
**self.access_token_request_data
**self.access_token_request_data,
},
}

Expand Down

0 comments on commit 41fff55

Please sign in to comment.