Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def api_call_with_auth(self, *args, **kwargs):
r = self.__api_request(*args, **kwargs)
# Try creating a new session if we get an auth error and retrying the failed request
if r.status_code == 401:
self.__logger.debug('Creating a new session and retrying failed request')
self.auth_create_session()
return self.__api_request(*args, **kwargs)
if self.renew_period < time.time() - self.__last_renew < 30 * 60:
self.__logger.debug('Automatically renewing session')
try:
self.auth_renew_session()
except EvaError as e:
raise EvaAutoRenewError('Failed to automatically renew, got error {}'.format(str(e)))
return r