Merge pull request #296 from CartoDB/add_timeouts_requests
Release python 0.9.4
This commit is contained in:
commit
e380d51bec
@ -14,6 +14,8 @@ class HereMapsGeocoder:
|
|||||||
STAGING_GEOCODE_JSON_URL = 'https://geocoder.cit.api.here.com/6.2/geocode.json'
|
STAGING_GEOCODE_JSON_URL = 'https://geocoder.cit.api.here.com/6.2/geocode.json'
|
||||||
DEFAULT_MAXRESULTS = 1
|
DEFAULT_MAXRESULTS = 1
|
||||||
DEFAULT_GEN = 9
|
DEFAULT_GEN = 9
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
ADDRESS_PARAMS = [
|
ADDRESS_PARAMS = [
|
||||||
'city',
|
'city',
|
||||||
@ -85,7 +87,8 @@ class HereMapsGeocoder:
|
|||||||
'gen': self.gen
|
'gen': self.gen
|
||||||
}
|
}
|
||||||
request_params.update(params)
|
request_params.update(params)
|
||||||
response = requests.get(self.host, params=request_params)
|
response = requests.get(self.host, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
return json.loads(response.text)
|
return json.loads(response.text)
|
||||||
elif response.status_code == requests.codes.bad_request:
|
elif response.status_code == requests.codes.bad_request:
|
||||||
|
@ -10,6 +10,8 @@ class HereMapsRoutingIsoline:
|
|||||||
PRODUCTION_ROUTING_BASE_URL = 'https://isoline.route.api.here.com'
|
PRODUCTION_ROUTING_BASE_URL = 'https://isoline.route.api.here.com'
|
||||||
STAGING_ROUTING_BASE_URL = 'https://isoline.route.cit.api.here.com'
|
STAGING_ROUTING_BASE_URL = 'https://isoline.route.cit.api.here.com'
|
||||||
ISOLINE_PATH = '/routing/7.2/calculateisoline.json'
|
ISOLINE_PATH = '/routing/7.2/calculateisoline.json'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
ACCEPTED_MODES = {
|
ACCEPTED_MODES = {
|
||||||
"walk": "pedestrian",
|
"walk": "pedestrian",
|
||||||
@ -50,7 +52,8 @@ class HereMapsRoutingIsoline:
|
|||||||
data_range,
|
data_range,
|
||||||
range_type,
|
range_type,
|
||||||
parsed_options)
|
parsed_options)
|
||||||
response = requests.get(self._url, params=request_params)
|
response = requests.get(self._url, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
return self.__parse_isolines_response(response.text)
|
return self.__parse_isolines_response(response.text)
|
||||||
elif response.status_code == requests.codes.bad_request:
|
elif response.status_code == requests.codes.bad_request:
|
||||||
|
@ -11,6 +11,8 @@ class MapzenGeocoder:
|
|||||||
'A Mapzen Geocoder wrapper for python'
|
'A Mapzen Geocoder wrapper for python'
|
||||||
|
|
||||||
BASE_URL = 'https://search.mapzen.com/v1/search'
|
BASE_URL = 'https://search.mapzen.com/v1/search'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
def __init__(self, app_key, logger, base_url=BASE_URL):
|
def __init__(self, app_key, logger, base_url=BASE_URL):
|
||||||
self._app_key = app_key
|
self._app_key = app_key
|
||||||
@ -24,7 +26,8 @@ class MapzenGeocoder:
|
|||||||
state_province,
|
state_province,
|
||||||
country, search_type)
|
country, search_type)
|
||||||
try:
|
try:
|
||||||
response = requests.get(self._url, params=request_params)
|
response = requests.get(self._url, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
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:
|
||||||
@ -41,6 +44,12 @@ class MapzenGeocoder:
|
|||||||
"state_province": state_province})
|
"state_province": state_province})
|
||||||
raise ServiceException('Error trying to geocode {0} using mapzen'.format(searchtext),
|
raise ServiceException('Error trying to geocode {0} using mapzen'.format(searchtext),
|
||||||
response)
|
response)
|
||||||
|
except requests.Timeout as te:
|
||||||
|
# In case of timeout we want to stop the job because the server
|
||||||
|
# could be down
|
||||||
|
self._logger.error('Timeout connecting to Mapzen geocoding server')
|
||||||
|
raise ServiceException('Error trying to geocode {0} using mapzen'.format(searchtext),
|
||||||
|
None)
|
||||||
except requests.ConnectionError as e:
|
except requests.ConnectionError as e:
|
||||||
# Don't raise the exception to continue with the geocoding job
|
# Don't raise the exception to continue with the geocoding job
|
||||||
self._logger.error('Error connecting to Mapzen geocoding server',
|
self._logger.error('Error connecting to Mapzen geocoding server',
|
||||||
|
@ -19,6 +19,8 @@ class MatrixClient:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
ONE_TO_MANY_URL = 'https://matrix.mapzen.com/one_to_many'
|
ONE_TO_MANY_URL = 'https://matrix.mapzen.com/one_to_many'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
def __init__(self, matrix_key, logger):
|
def __init__(self, matrix_key, logger):
|
||||||
self._matrix_key = matrix_key
|
self._matrix_key = matrix_key
|
||||||
@ -41,7 +43,8 @@ class MatrixClient:
|
|||||||
'costing': costing,
|
'costing': costing,
|
||||||
'api_key': self._matrix_key
|
'api_key': self._matrix_key
|
||||||
}
|
}
|
||||||
response = requests.get(self.ONE_TO_MANY_URL, params=request_params)
|
response = requests.get(self.ONE_TO_MANY_URL, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
|
|
||||||
if response.status_code != requests.codes.ok:
|
if response.status_code != 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',
|
||||||
|
@ -11,6 +11,8 @@ class MapzenRouting:
|
|||||||
'A Mapzen Routing wrapper for python'
|
'A Mapzen Routing wrapper for python'
|
||||||
|
|
||||||
PRODUCTION_ROUTING_BASE_URL = 'https://valhalla.mapzen.com/route'
|
PRODUCTION_ROUTING_BASE_URL = 'https://valhalla.mapzen.com/route'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
ACCEPTED_MODES = {
|
ACCEPTED_MODES = {
|
||||||
"walk": "pedestrian",
|
"walk": "pedestrian",
|
||||||
@ -43,7 +45,8 @@ class MapzenRouting:
|
|||||||
mode_param,
|
mode_param,
|
||||||
units)
|
units)
|
||||||
request_params = self.__parse_request_parameters(json_request_params)
|
request_params = self.__parse_request_parameters(json_request_params)
|
||||||
response = requests.get(self._url, params=request_params)
|
response = requests.get(self._url, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
return self.__parse_routing_response(response.text)
|
return self.__parse_routing_response(response.text)
|
||||||
elif response.status_code == requests.codes.bad_request:
|
elif response.status_code == requests.codes.bad_request:
|
||||||
|
@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.9.3',
|
version='0.9.4',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user