diff options
author | Baudouin Raoult <baudouin.raoult@ecmwf.int> | 2018-05-23 12:04:17 +0200 |
---|---|---|
committer | Baudouin Raoult <baudouin.raoult@ecmwf.int> | 2018-05-23 12:04:17 +0200 |
commit | 01ef73a38504cc9444d82b7d5c41bb61b06b5698 (patch) | |
tree | c4c7dbca2aef3249698fd76700ae5d42efb42cf9 /cdsapi/api.py | |
parent | 3497d5dbee021dbf441a85049771578a7a28472b (diff) | |
parent | 11a74dd1a24b3a2d7d1000f85c25c6fc7f60099e (diff) |
Merge branch 'master' of https://software.ecmwf.int/stash/scm/cds/cdsapi
Diffstat (limited to 'cdsapi/api.py')
-rw-r--r-- | cdsapi/api.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/cdsapi/api.py b/cdsapi/api.py index 983f4bc..5ea1a48 100644 --- a/cdsapi/api.py +++ b/cdsapi/api.py @@ -213,7 +213,7 @@ class Client(object): if n.strip() == '' and not self.full_stack: break self.logger.error(" %s", n) - raise Exception(reply['error'].get('reason')) + raise Exception("%s. %s." % (reply['error'].get('message'), reply['error'].get('reason'))) raise Exception('Unknown API state [%s]' % (reply['state'],)) @@ -234,14 +234,21 @@ class Client(object): def wrapped(*args, **kwargs): tries = 0 while tries < self.retry_max: - r = call(*args, **kwargs) - if not retriable(r.status_code, r.reason): - return r + try: + r = call(*args, **kwargs) + except requests.exceptions.ConnectionError as e: + r = None + self.logger.warning("Recovering from connection error [%s], attemps %s of %s", + e, tries, self.retry_max) + + if r is not None: + if not retriable(r.status_code, r.reason): + return r + self.logger.warning("Recovering from HTTP error [%s %s], attemps %s of %s", + r.status_code, r.reason, tries, self.retry_max) tries += 1 - self.logger.warning("Recovering from HTTP error [%s %s], attemps %s of %s", - r.status_code, r.reason, tries, self.retry_max) self.logger.warning("Retrying in %s second (", self.sleep_max) time.sleep(self.sleep_max) |