Showing
1 changed file
with
10 additions
and
2 deletions
1 | 1 | from openprocurement_client.client import Client, EDRClient |
2 | 2 | from openprocurement_client.utils import get_tender_id_by_uaid |
3 | 3 | from openprocurement_client.exceptions import IdNotFound |
4 | -from restkit.errors import RequestFailed, BadStatusLine | |
4 | +from restkit.errors import RequestFailed, BadStatusLine, ResourceError | |
5 | 5 | from retrying import retry |
6 | +from time import sleep | |
6 | 7 | import os |
7 | 8 | import urllib |
8 | 9 | |
... | ... | @@ -32,7 +33,14 @@ class StableEDRClient(EDRClient): |
32 | 33 | @retry(stop_max_attempt_number=100, wait_random_min=500, |
33 | 34 | wait_random_max=4000, retry_on_exception=retry_if_request_failed) |
34 | 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 | 46 | def prepare_edr_wrapper(host_url, api_version, username, password): | ... | ... |
Please
register
or
login
to post a comment