def handle_api_result(self, info, kwargs=None, sleeper=None): if sleeper is None: sleeper = self.sleepers.make() try: userinfo = info['query']['userinfo'] except KeyError: userinfo = () if 'blockedby' in userinfo: self.blocked = (userinfo['blockedby'], userinfo.get('blockreason', u'')) else: self.blocked = False self.hasmsg = 'messages' in userinfo self.logged_in = 'anon' not in userinfo if 'error' in info: if info['error']['code'] in {u'internal_api_error_DBConnectionError', u'internal_api_error_DBQueryError'}: sleeper.sleep() return False if '*' in info['error']: raise errors.APIError(info['error']['code'], info['error']['info'], info['error']['*']) raise errors.APIError(info['error']['code'], info['error']['info'], kwargs) return True
def handle_api_result(self, info, kwargs=None, sleeper=None): if sleeper is None: sleeper = self.sleepers.make() try: userinfo = info['query']['userinfo'] except KeyError: userinfo = () if 'blockedby' in userinfo: self.blocked = (userinfo['blockedby'], userinfo.get('blockreason', u'')) else: self.blocked = False self.hasmsg = 'messages' in userinfo self.logged_in = 'anon' not in userinfo if 'warnings' in info: for module, warning in info['warnings'].items(): if '*' in warning: log.warning(warning['*']) if 'error' in info: if info['error'].get('code') in { u'internal_api_error_DBConnectionError', u'internal_api_error_DBQueryError' }: sleeper.sleep() return False # cope with https://phabricator.wikimedia.org/T106066 if (info['error'].get('code') == u'mwoauth-invalid-authorization' and 'Nonce already used' in info['error'].get('info')): log.warning( 'retrying due to nonce error https://phabricator.wikimedia.org/T106066' ) sleeper.sleep() return False if 'query' in info['error']: # Semantic Mediawiki does not follow the standard error format raise errors.APIError(None, info['error']['query'], kwargs) if '*' in info['error']: raise errors.APIError(info['error']['code'], info['error']['info'], info['error']['*']) raise errors.APIError(info['error']['code'], info['error']['info'], kwargs) return True