Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pydomo/Transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def __init__(self, client_id, client_secret, api_host, use_https, logger, reques
self.clientId = client_id
self.clientSecret = client_secret
self.logger = logger
self._renew_access_token()
self.request_timeout = request_timeout
self._renew_access_token()

@staticmethod
def _build_apihost(host, use_https):
Expand Down Expand Up @@ -84,8 +84,15 @@ def request(self, url, method, headers, params=None, body=None):

def _renew_access_token(self):
self.logger.debug("Renewing Access Token")
url = self.apiHost + '/oauth/token?grant_type=client_credentials'
response = requests.post(url=url, auth=HTTPBasicAuth(self.clientId, self.clientSecret))
request_args = {
'method': HTTPMethod.POST,
'url': self.apiHost + '/oauth/token?grant_type=client_credentials',
'auth': HTTPBasicAuth(self.clientId, self.clientSecret)
}
if self.request_timeout:
request_args['timeout'] = self.request_timeout

response = requests.request(**request_args)
if response.status_code == requests.codes.OK:
self.access_token = response.json()['access_token']
self.token_expiration = self._extract_expiration(self.access_token)
Expand Down