Пример #1
0
def check_auth(body, indexer):
    if '<error code="100"' in body:
        raise IndexerAuthException("The API key seems to be incorrect.",
                                   indexer)
    if '<error code="101"' in body:
        raise IndexerAuthException("The account seems to be suspended.",
                                   indexer)
    if '<error code="102"' in body:
        raise IndexerAuthException("You're not allowed to use the API.",
                                   indexer)
    if '<error code="910"' in body:
        raise IndexerAccessException(
            "The API seems to be disabled for the moment.", indexer)
    if "Site Maintenance" in body:
        raise IndexerAccessException("Site is down for maintenance.", indexer)
    if '<error code=' in body:
        try:
            tree = ET.fromstring(body)
            code = tree.attrib["code"]
            description = tree.attrib["description"]
            if "Request limit reached" in body:
                raise IndexerApiLimitReachedException("API limit reached",
                                                      indexer)
            logger.error(
                "Indexer %s returned unknown error code %s with description: %s"
                % (indexer, code, description))
            exception = IndexerAccessException(
                "Unknown error while trying to access the indexer: %s" %
                description, indexer)
        except Exception:
            logger.error("Indexer %s returned an error page: %s" %
                         (indexer, body))
            exception = IndexerAccessException(
                "Unknown error while trying to access the indexer.", indexer)
        raise exception
Пример #2
0
def test_connection(apikey, username):
    logger.info("Testing connection for omgwtfnzbs")
    f = furl(config.settings.indexers.omgwtfnzbs.host)
    f.path.add("xml")
    f = f.add({"api": apikey, "user": username})
    try:
        headers = {'User-Agent': config.settings.searching.userAgent}
        r = requests.get(f.url,
                         verify=False,
                         headers=headers,
                         timeout=config.settings.searching.timeout)
        r.raise_for_status()
        if "your user/api information is incorrect" in r.text:
            raise IndexerAuthException("Wrong credentials", None)
    except RequestException as e:
        logger.info("Unable to connect to indexer using URL %s: %s" %
                    (f.url, str(e)))
        return False, "Unable to connect to host"
    except IndexerAuthException:
        logger.info(
            "Unable to log in to indexer omgwtfnzbs due to wrong credentials")
        return False, "Wrong credentials"
    except IndexerAccessException as e:
        logger.info(
            "Unable to log in to indexer omgwtfnzbs. Unknown error %s." %
            str(e))
        return False, "Host reachable but unknown error returned"
    return True, ""
Пример #3
0
 def check_auth(self, xml):
     if "your user/api information is incorrect.. check and try again" in xml:
         raise IndexerAuthException("Wrong API key or username", None)
     if "applying some updates please try again later." in xml:
         raise IndexerAccessException("Indexer down for maintenance", None)