def fivehundred_error(self, request): self.req_500_err[request] = set_timestamp() get_property(self.req_500_err_prop, dumps(self.req_500_err)) kodi_log(u'ConnectionError: {}\nSuppressing retries for 1 minute'.format(dumps(self.req_500_err)), 1) xbmcgui.Dialog().notification( ADDON.getLocalizedString(32308).format(self.req_api_name), ADDON.getLocalizedString(32307))
def connection_error(self, err): self.req_connect_err = set_timestamp() get_property(self.req_connect_err_prop, self.req_connect_err) kodi_log(u'ConnectionError: {}\nSuppressing retries for 1 minute'.format(err), 1) xbmcgui.Dialog().notification( ADDON.getLocalizedString(32308).format(self.req_api_name), ADDON.getLocalizedString(32307))
def refresh_token(self): # Check we haven't attempted too many refresh attempts refresh_attempts = try_int(get_property('TraktRefreshAttempts')) + 1 if refresh_attempts > 5: kodi_log( 'Trakt Unauthorised!\nExceeded refresh_token attempt limit\nSuppressing retries for 10 minutes', 1) get_property('TraktRefreshTimeStamp', set_timestamp(600)) get_property('TraktRefreshAttempts', 0) # Reset refresh attempts return get_property('TraktRefreshAttempts', refresh_attempts) kodi_log('Attempting to refresh Trakt token', 2) if not self.authorization or not self.authorization.get( 'refresh_token'): kodi_log('Trakt refresh token not found!', 1) return postdata = { 'refresh_token': self.authorization.get('refresh_token'), 'client_id': self.client_id, 'client_secret': self.client_secret, 'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 'grant_type': 'refresh_token' } self.authorization = self.get_api_request_json( 'https://api.trakt.tv/oauth/token', postdata=postdata) if not self.authorization or not self.authorization.get( 'access_token'): kodi_log('Failed to refresh Trakt token!', 2) return self.on_authenticated(auth_dialog=False) kodi_log('Trakt token refreshed', 1) return self.authorization
def connection_error(self, err, wait_time=30, msg_affix=''): self.req_connect_err = set_timestamp(wait_time) get_property(self.req_connect_err_prop, self.req_connect_err) kodi_log( u'ConnectionError: {} {}\nSuppressing retries for 30 seconds'. format(msg_affix, err), 1) xbmcgui.Dialog().notification( ADDON.getLocalizedString(32308).format(' '.join( [self.req_api_name, msg_affix])), ADDON.getLocalizedString(32307).format('30'))
def timeout_error(self, err): """ Log timeout error If two timeouts occur in x3 the timeout limit then set connection error e.g. if timeout limit is 10s then two timeouts within 30s trigger connection error """ kodi_log(u'ConnectionTimeOut: {}'.format(err), 1) if get_timestamp(self.req_timeout_err): self.connection_error(err, msg_affix='timeout') self.req_timeout_err = set_timestamp(self.timeout * 3) get_property(self.req_timeout_err_prop, self.req_timeout_err)
def timeout_error(self, err): """ Log timeout error - if two in one minute set connection error """ if get_timestamp(self.req_timeout_err): self.connection_error(err) self.req_timeout_err = set_timestamp() get_property(self.req_timeout_err_prop, self.req_timeout_err)