From f0a9779a8ded1e19492ea60f0a43abd391563682 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 4 Mar 2019 15:41:24 +0100 Subject: [PATCH 1/2] Detect alternative TomTom rate limit header Also flexibilizes detection by making it case-insensitive and allowing for text around the message Fixes 545 --- .../cartodb_services/cartodb_services/tools/qps.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/tools/qps.py b/server/lib/python/cartodb_services/cartodb_services/tools/qps.py index 9ae3abd..cd52f96 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tools/qps.py +++ b/server/lib/python/cartodb_services/cartodb_services/tools/qps.py @@ -2,13 +2,17 @@ import time import random from datetime import datetime from exceptions import TimeoutException +import re DEFAULT_RETRY_TIMEOUT = 60 DEFAULT_QUERIES_PER_SECOND = 10 -TOMTOM_403_RATE_LIMIT_HEADER = 'Account Over Queries Per Second Limit' +TOMTOM_403_RATE_LIMIT_HEADERS = [ + 'Account Over Queries Per Second Limit', + 'Developer Over Qps' +] TOMTOM_DETAIL_HEADER = 'X-Error-Detail-Header' - +TOMTOM_403_RATE_LIMIT_HEADER_PATTERN = re.compile('|'.join(TOMTOM_403_RATE_LIMIT_HEADERS), re.IGNORECASE) def qps_retry(original_function=None, **options): """ Query Per Second retry decorator @@ -49,9 +53,11 @@ class QPSService: response = getattr(e, 'response', None) if response is not None: if self._provider is not None and self._provider == 'tomtom' and (response.status_code == 403): - if response.headers.get(TOMTOM_DETAIL_HEADER) != TOMTOM_403_RATE_LIMIT_HEADER: + detail_header = response.headers.get(TOMTOM_DETAIL_HEADER) + if detail_header and TOMTOM_403_RATE_LIMIT_HEADER_PATTERN.search(detail_header): + self.retry(start_time, attempt_number) + else: raise e - self.retry(start_time, attempt_number) elif response.status_code == 429: self.retry(start_time, attempt_number) else: From 45542b2f28c1748b8ee6905c54c50dc585656dae Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 4 Mar 2019 18:25:25 +0100 Subject: [PATCH 2/2] Release new python lib version --- NEWS.md | 5 +++++ server/lib/python/cartodb_services/setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 4755034..0b19901 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +Mar 4th, 2019 +============== +* Version `0.21.2` of the python library + * Fixed TomTom Qps respondes (#546) + Feb 25th, 2019 ============== * Version `0.26.2` of the client extension diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index 8985b8b..2bb7691 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.21.1', + version='0.21.2', description='CartoDB Services API Python Library',