How to use the censys.base.CensysJSONDecodeException function in censys

To help you get started, we’ve selected a few censys 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 censys / censys-python / censys / base.py View on Github external
else:
            url = "/".join((self._api_url, endpoint))
        args = args or {}
        if data:
            data = json.dumps(data or {})
            res = method(url, params=args, data=data)
        else:
            res = method(url, params=args)
        if res.status_code == 200:
            return res.json()
        else:
            try:
                message = res.json()["error"]
                const = res.json().get("error_type", None)
            except ValueError:
                raise CensysJSONDecodeException(
                        status_code=res.status_code,
                        message="Censys response is not valid JSON and cannot be decoded.",
                        headers=res.headers,
                        body=res.text,
                        const="badjson"
                )
            except KeyError:
                message = None
                const = "unknown"
            censys_exception = self._get_exception_class(res.status_code)
            raise censys_exception(
                status_code=res.status_code,
                message=message,
                headers=res.headers,
                body=res.text,
                const=const)
github sdnewhop / grinder / grinder / censysconnector.py View on Github external
) -> None:
        """
        This function is used to search hosts in Censys with initialized API
        :param query: query that you want to use for you search
        :param max_records: quantity of hosts that you want to get with query
        :return: None
        """
        try:
            self.results = list(
                self.api.search(
                    query, fields=self.search_fields, max_records=max_records
                )
            )
        except (
            CensysRateLimitExceededException,
            CensysJSONDecodeException,
            CensysNotFoundException,
            CensysUnauthorizedException,
        ) as api_error:
            print(f"Censys API error: {api_error}")
        except AttributeError as api_not_defined:
            print(f"Censys API was not initialized: {api_not_defined}")
        except CensysException as too_much_results_required:
            if "Only the first 1,000 search results are available" in str(
                too_much_results_required
            ):
                print(
                    "Only the first 1,000 search results are available. Retry search with 1,000 results limit."
                )
                self.search(
                    query, max_records=DefaultValues.CENSYS_FREE_PLAN_RESULTS_QUANTITY
                )