How to use the googlemaps.exceptions.HTTPError function in googlemaps

To help you get started, we’ve selected a few googlemaps 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 googlemaps / google-maps-services-python / test / test_client.py View on Github external
def test_transport_error(self):
        responses.add(responses.GET,
                      "https://maps.googleapis.com/maps/api/geocode/json",
                      status=404,
                      content_type='application/json')

        client = googlemaps.Client(key="AIzaasdf")
        with self.assertRaises(googlemaps.exceptions.HTTPError) as e:
            client.geocode("Foo")

        self.assertEqual(e.exception.status_code, 404)
github googlemaps / google-maps-services-python / test / test_client.py View on Github external
def test_transport_error(self):
        responses.add(responses.GET,
                      "https://maps.googleapis.com/maps/api/geocode/json",
                      status=404,
                      content_type='application/json')

        client = googlemaps.Client(key="AIzaasdf")
        with self.assertRaises(googlemaps.exceptions.HTTPError) as e:
            client.geocode("Foo")

        self.assertEqual(e.exception.status_code, 404)
github googlemaps / google-maps-services-python / googlemaps / client.py View on Github external
def _get_body(self, response):
        if response.status_code != 200:
            raise googlemaps.exceptions.HTTPError(response.status_code)

        body = response.json()

        api_status = body["status"]
        if api_status == "OK" or api_status == "ZERO_RESULTS":
            return body

        if api_status == "OVER_QUERY_LIMIT":
            raise googlemaps.exceptions._OverQueryLimit(
                api_status, body.get("error_message"))

        raise googlemaps.exceptions.ApiError(api_status,
                                             body.get("error_message"))
github hzlmn / aiogmaps / aiogmaps / client.py View on Github external
async def _get_body(self, response):
        if response.status != 200:
            raise googlemaps.exceptions.HTTPError(response.status)

        body = await response.json()

        api_status = body['status']
        if api_status == 'OK' or api_status == 'ZERO_RESULTS':
            return body

        if api_status == 'OVER_QUERY_LIMIT':
            raise googlemaps.exceptions._OverQueryLimit(
                api_status, body.get('error_message'))

        raise googlemaps.exceptions.ApiError(api_status,
                                             body.get('error_message'))
github peeringdb / peeringdb / peeringdb_server / models.py View on Github external
"street_address" in result[0]["types"]
                or "establishment" in result[0]["types"]
                or "premise" in result[0]["types"]
                or "subpremise" in result[0]["types"]
            ):
                loc = result[0].get("geometry").get("location")
                self.latitude = loc.get("lat")
                self.longitude = loc.get("lng")
                self.geocode_error = None
            else:
                self.latitude = None
                self.longitude = None
                self.geocode_error = _("Address not found")
            self.geocode_status = True
            return result
        except (googlemaps.exceptions.HTTPError, googlemaps.exceptions.ApiError), inst:
            self.geocode_error = str(inst)
            self.geocode_status = True
        except googlemaps.exceptions.Timeout, inst:
            self.geocode_error = _("API Timeout")
            self.geocode_status = False
        finally:
            self.geocode_date = datetime.datetime.now().replace(tzinfo=UTC())
            if save:
                self.save()
github googlemaps / google-maps-services-python / googlemaps / client.py View on Github external
try:
            resp = requests.get(_BASE_URL + url,
                headers={"User-Agent": _USER_AGENT},
                timeout=self.timeout,
                verify=True) # NOTE(cbro): verify SSL certs.
        except requests.exceptions.Timeout:
            raise googlemaps.exceptions.Timeout()
        except Exception as e:
            raise googlemaps.exceptions.TransportError(e)

        if resp.status_code in _RETRIABLE_STATUSES:
            # Retry request.
            return self._get(url, params, first_request_time, retry_counter + 1)

        if resp.status_code != 200:
            raise googlemaps.exceptions.HTTPError(resp.status_code)

        body = resp.json()

        api_status = body["status"]
        if api_status == "OK" or api_status == "ZERO_RESULTS":
            return body

        if api_status == "OVER_QUERY_LIMIT":
            # Retry request.
            return self._get(url, params, first_request_time, retry_counter + 1)

        if "error_message" in body:
            raise googlemaps.exceptions.ApiError(api_status,
                    body["error_message"])
        else:
            raise googlemaps.exceptions.ApiError(api_status)
github googlemaps / google-maps-services-python / googlemaps / roads.py View on Github external
"Received a malformed response.")

    if "error" in j:
        error = j["error"]
        status = error["status"]

        if status == "RESOURCE_EXHAUSTED":
            raise googlemaps.exceptions._RetriableRequest()

        if "message" in error:
            raise googlemaps.exceptions.ApiError(status, error["message"])
        else:
            raise googlemaps.exceptions.ApiError(status)

    if resp.status_code != 200:
        raise googlemaps.exceptions.HTTPError(resp.status_code)

    return j