Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def keepalive(self):
"""Makes a keepalive request to avoid session timeout.
Raises SessionTimedOut if the session has timed out.
"""
url = self._default_url
resp = self._session.get(url, timeout=self._timeout)
if resp.status_code != 200:
_LOG.info('Session timed out')
raise SessionTimedOut('Session timed out')
_LOG.info('Session refreshed')
def __init__(self, username, password, timeout=30,
session=None):
self._username = username
self._password = password
self._session = session or self._get_session()
self._session.headers['X-Requested-With'] = 'XMLHttpRequest'
self._timeout = timeout
self._locations = {}
self._baseurl = 'https://www.mytotalconnectcomfort.com/portal'
self._default_url = self._baseurl
try:
# Something changed recently, so just always act like we're
# timed out on startup
raise SessionTimedOut()
self.keepalive()
except SessionTimedOut:
self._session.cookies.clear()
self._login()
self._discover()
def _retries_login(self):
try:
self.keepalive()
except SessionTimedOut:
self._login()
yield