How to use the ipinfo.exceptions.RequestQuotaExceededError function in ipinfo

To help you get started, we’ve selected a few ipinfo 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 ipinfo / python / ipinfo / handler.py View on Github external
def _requestDetails(self, ip_address=None):
        """Get IP address data by sending request to IPinfo API."""
        if ip_address not in self.cache:
            url = self.API_URL
            if ip_address:
                url += "/" + ip_address

            response = requests.get(
                url, headers=self._get_headers(), **self.request_options
            )
            if response.status_code == 429:
                raise RequestQuotaExceededError()
            response.raise_for_status()
            self.cache[ip_address] = response.json()

        return self.cache[ip_address]
github ipinfo / python / ipinfo / handler.py View on Github external
lookup_addresses = []
        for ip_address in ip_addresses:
            if ip_address in self.cache:
                result[ip_address] = self.cache[ip_address]
            else:
                lookup_addresses.append(ip_address)

        # Do the lookup
        url = self.API_URL + "/batch"
        headers = self._get_headers()
        headers["content-type"] = "application/json"
        response = requests.post(
            url, json=lookup_addresses, headers=headers, **self.request_options
        )
        if response.status_code == 429:
            raise RequestQuotaExceededError()
        response.raise_for_status()

        # Fill up cache
        json_response = response.json()
        for ip_address, details in json_response.items():
            self.cache[ip_address] = details

        # Merge cached results with new lookup
        result.update(json_response)

        # Format every result
        for detail in result.values():
            if isinstance(detail, dict):
                self._format_details(detail)

        return result