How to use the greynoise.exceptions.RateLimitError function in greynoise

To help you get started, we’ve selected a few greynoise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GreyNoise-Intelligence / pygreynoise / tests / test_api.py View on Github external
def test_rate_limit_error(self, client):
        """Exception is raised on rate limit response."""
        client.session = Mock()
        response = client.session.get()
        response.headers.get.return_value = "application/json"
        response.status_code = 429
        with pytest.raises(RateLimitError):
            client._request("endpoint")
github GreyNoise-Intelligence / pygreynoise / src / greynoise / api / __init__.py View on Github external
)
        content_type = response.headers.get("Content-Type", "")
        if "application/json" in content_type:
            body = response.json()
        else:
            body = response.text

        LOGGER.debug(
            "API response received",
            status_code=response.status_code,
            content_type=content_type,
            body=body,
        )

        if response.status_code == 429:
            raise RateLimitError()
        if response.status_code >= 400:
            raise RequestFailure(response.status_code, body)

        return body
github GreyNoise-Intelligence / pygreynoise / src / greynoise / api.py View on Github external
}
        url = "/".join([self.BASE_URL, self.API_VERSION, endpoint])
        LOGGER.msg(
            "Sending API request...", url=url, params=params, json=json, level="debug"
        )
        response = self.session.get(
            url, headers=headers, timeout=self.timeout, params=params, json=json
        )

        if "application/json" in response.headers.get("Content-Type", ""):
            body = response.json()
        else:
            body = response.text

        if response.status_code == 429:
            raise RateLimitError()
        if response.status_code >= 400:
            raise RequestFailure(response.status_code, body)

        return body