Showing
1 changed file
with
10 additions
and
2 deletions
1 | from openprocurement_client.client import Client, EDRClient | 1 | from openprocurement_client.client import Client, EDRClient |
2 | from openprocurement_client.utils import get_tender_id_by_uaid | 2 | from openprocurement_client.utils import get_tender_id_by_uaid |
3 | from openprocurement_client.exceptions import IdNotFound | 3 | from openprocurement_client.exceptions import IdNotFound |
4 | -from restkit.errors import RequestFailed, BadStatusLine | 4 | +from restkit.errors import RequestFailed, BadStatusLine, ResourceError |
5 | from retrying import retry | 5 | from retrying import retry |
6 | +from time import sleep | ||
6 | import os | 7 | import os |
7 | import urllib | 8 | import urllib |
8 | 9 | ||
@@ -32,7 +33,14 @@ class StableEDRClient(EDRClient): | @@ -32,7 +33,14 @@ class StableEDRClient(EDRClient): | ||
32 | @retry(stop_max_attempt_number=100, wait_random_min=500, | 33 | @retry(stop_max_attempt_number=100, wait_random_min=500, |
33 | wait_random_max=4000, retry_on_exception=retry_if_request_failed) | 34 | wait_random_max=4000, retry_on_exception=retry_if_request_failed) |
34 | def request(self, *args, **kwargs): | 35 | def request(self, *args, **kwargs): |
35 | - return super(StableEDRClient, self).request(*args, **kwargs) | 36 | + try: |
37 | + res = super(StableEDRClient, self).request(*args, **kwargs) | ||
38 | + except ResourceError as re: | ||
39 | + if re.status_int == 429: | ||
40 | + sleep(int(re.response.headers.get('Retry-After', '30'))) | ||
41 | + raise re | ||
42 | + else: | ||
43 | + return res | ||
36 | 44 | ||
37 | 45 | ||
38 | def prepare_edr_wrapper(host_url, api_version, username, password): | 46 | def prepare_edr_wrapper(host_url, api_version, username, password): |
Please
register
or
login
to post a comment