How to use the geoip2.errors.HTTPError function in geoip2

To help you get started, we’ve selected a few geoip2 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 maxmind / GeoIP2-python / geoip2 / webservice.py View on Github external
def _exception_for_5xx_status(self, status, uri):
        return HTTPError(
            'Received a server error (%(status)i) for '
            '%(uri)s' % locals(), status, uri)
github maxmind / GeoIP2-python / geoip2 / webservice.py View on Github external
elif response.headers['Content-Type'].find('json') == -1:
            return HTTPError(
                'Received a %i for %s with the following '
                'body: %s' % (status, uri, response.content), status, uri)
        try:
            body = response.json()
        except ValueError as ex:
            return HTTPError(
                'Received a %(status)i error for %(uri)s but it did'
                ' not include the expected JSON body: ' % locals() +
                ', '.join(ex.args), status, uri)
        else:
            if 'code' in body and 'error' in body:
                return self._exception_for_web_service_error(
                    body.get('error'), body.get('code'), status, uri)
            return HTTPError(
                'Response contains JSON but it does not specify '
                'code or error keys', status, uri)
github maxmind / GeoIP2-python / geoip2 / errors.py View on Github external
def __init__(self, message, http_status=None, uri=None):
        super(HTTPError, self).__init__(message)
        self.http_status = http_status
        self.uri = uri
github maxmind / GeoIP2-python / geoip2 / webservice.py View on Github external
def _exception_for_non_200_status(self, status, uri):
        return HTTPError(
            'Received a very surprising HTTP status '
            '(%(status)i) for %(uri)s' % locals(), status, uri)
github maxmind / GeoIP2-python / geoip2 / webservice.py View on Github external
def _exception_for_4xx_status(self, response, status, uri):
        if not response.content:
            return HTTPError(
                'Received a %(status)i error for %(uri)s '
                'with no body.' % locals(), status, uri)
        elif response.headers['Content-Type'].find('json') == -1:
            return HTTPError(
                'Received a %i for %s with the following '
                'body: %s' % (status, uri, response.content), status, uri)
        try:
            body = response.json()
        except ValueError as ex:
            return HTTPError(
                'Received a %(status)i error for %(uri)s but it did'
                ' not include the expected JSON body: ' % locals() +
                ', '.join(ex.args), status, uri)
        else:
            if 'code' in body and 'error' in body:
                return self._exception_for_web_service_error(
                    body.get('error'), body.get('code'), status, uri)
            return HTTPError(
                'Response contains JSON but it does not specify '
                'code or error keys', status, uri)
github maxmind / GeoIP2-python / geoip2 / webservice.py View on Github external
def _exception_for_4xx_status(self, response, status, uri):
        if not response.content:
            return HTTPError(
                'Received a %(status)i error for %(uri)s '
                'with no body.' % locals(), status, uri)
        elif response.headers['Content-Type'].find('json') == -1:
            return HTTPError(
                'Received a %i for %s with the following '
                'body: %s' % (status, uri, response.content), status, uri)
        try:
            body = response.json()
        except ValueError as ex:
            return HTTPError(
                'Received a %(status)i error for %(uri)s but it did'
                ' not include the expected JSON body: ' % locals() +
                ', '.join(ex.args), status, uri)
        else:
            if 'code' in body and 'error' in body:
                return self._exception_for_web_service_error(