Add more logs for mapzen services

This commit is contained in:
Mario de Frutos 2016-08-17 11:41:29 +02:00
parent 46c96e02b4
commit 3cc4e06420
6 changed files with 52 additions and 19 deletions

View File

@ -57,9 +57,14 @@ class HereMapsRoutingIsoline:
return [] return []
else: else:
self._logger.error('Error trying to calculate HERE isolines', self._logger.error('Error trying to calculate HERE isolines',
data={"response": response.json(), "source": data={"response_status": response.status_code,
source, "mode": mode, "data_range": "response_reason": response.reason,
data_range, "range_type": range_type, "response_content": response.text,
"reponse_url": response.url,
"response_headers": response.headers,
"source": source, "mode": mode,
"data_range": data_range,
"range_type": range_type,
"options": options}) "options": options})
raise Exception('Error trying to calculate HERE isolines') raise Exception('Error trying to calculate HERE isolines')

View File

@ -19,14 +19,32 @@ class MapzenGeocoder:
@qps_retry @qps_retry
def geocode(self, searchtext, city=None, state_province=None, country=None): def geocode(self, searchtext, city=None, state_province=None, country=None):
request_params = self._build_requests_parameters(searchtext, city, state_province, country) request_params = self._build_requests_parameters(searchtext, city,
state_province,
country)
try:
response = requests.get(self._url, params=request_params) response = requests.get(self._url, params=request_params)
if response.status_code == requests.codes.ok: if response.status_code == requests.codes.ok:
return self.__parse_response(response.text) return self.__parse_response(response.text)
elif response.status_code == requests.codes.bad_request: elif response.status_code == requests.codes.bad_request:
return [] return []
else: else:
self._logger.error('Error trying to geocode using mapzen',
data={"response_status": response.status_code,
"response_reason": response.reason,
"response_content": response.text,
"reponse_url": response.url,
"response_headers": response.headers,
"searchtext": searchtext,
"city": city, "country": country,
"state_province": state_province })
raise Exception('Error trying to geocode {0} using mapzen'.format(searchtext)) raise Exception('Error trying to geocode {0} using mapzen'.format(searchtext))
except requests.ConnectionError as e:
# Don't raise the exception to continue with the geocoding job
self._logger.error('Error connecting to Mapzen geocoding server',
exception=e)
return []
def _build_requests_parameters(self, searchtext, city=None, def _build_requests_parameters(self, searchtext, city=None,
state_province=None, country=None): state_province=None, country=None):

View File

@ -44,8 +44,13 @@ class MatrixClient:
if not requests.codes.ok: if not requests.codes.ok:
self._logger.error('Error trying to get matrix distance from mapzen', self._logger.error('Error trying to get matrix distance from mapzen',
data={"response": response, "locations": data={"response_status": response.status_code,
locations, "costing": costing}) "response_reason": response.reason,
"response_content": response.text,
"reponse_url": response.url,
"response_headers": response.headers,
"locations": locations,
"costing": costing})
raise Exception('Error trying to get matrix distance from mapzen') raise Exception('Error trying to get matrix distance from mapzen')
return response.json() return response.json()

View File

@ -26,7 +26,8 @@ class QPSService:
try: try:
return fn(*args, **kwargs) return fn(*args, **kwargs)
except Exception as e: except Exception as e:
if hasattr(e, 'response') and (e.response.status_code == 429): response = getattr(e, 'response', None)
if response and (response.status_code == 429):
self.retry(start_time, attempt_number) self.retry(start_time, attempt_number)
else: else:
raise e raise e

View File

@ -49,11 +49,15 @@ class MapzenRouting:
elif response.status_code == requests.codes.bad_request: elif response.status_code == requests.codes.bad_request:
return MapzenRoutingResponse(None, None, None) return MapzenRoutingResponse(None, None, None)
else: else:
self._logger.error('Error trying to calculate route using HERE', self._logger.error('Error trying to calculate route using Mapzen',
data={"response": response.json(), "waypoints": data={"response_status": response.status_code,
waypoints, "mode": mode, "options": "response_reason": response.reason,
options}) "response_content": response.text,
raise Exception('Error trying to calculate route using HERE') "reponse_url": response.url,
"response_headers": response.headers,
"waypoints": waypoints, "mode": mode,
"options": options})
raise Exception('Error trying to calculate route using Mapzen')
def __parse_options(self, options): def __parse_options(self, options):
return dict(option.split('=') for option in options) return dict(option.split('=') for option in options)

View File

@ -10,7 +10,7 @@ from setuptools import setup, find_packages
setup( setup(
name='cartodb_services', name='cartodb_services',
version='0.7.4.1', version='0.7.4.2',
description='CartoDB Services API Python Library', description='CartoDB Services API Python Library',