diff options
author | Alessandro Amici <a.amici@bopen.eu> | 2018-06-22 15:31:14 +0200 |
---|---|---|
committer | Alessandro Amici <a.amici@bopen.eu> | 2018-06-22 15:31:14 +0200 |
commit | a49e8ce7837db4fd92d6ab8ba491deb7154d4b5e (patch) | |
tree | cd04e6fe8c17913ece9b8262cc79905ea44b5469 /cdsapi | |
parent | aefff0fe683d4a3b7f222f3b667a34185e37bb3f (diff) |
Do not depend on the Request object being a context manager (introduced in requests >= 2.18.0)
Diffstat (limited to 'cdsapi')
-rw-r--r-- | cdsapi/api.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/cdsapi/api.py b/cdsapi/api.py index 662dec9..9160916 100644 --- a/cdsapi/api.py +++ b/cdsapi/api.py @@ -64,7 +64,8 @@ class Result(object): self.info("Downloading %s to %s (%s)", url, target, bytes_to_string(size)) start = time.time() - with self.robust(requests.get)(url, stream=True, verify=self.verify) as r: + r = self.robust(requests.get)(url, stream=True, verify=self.verify) + try: r.raise_for_status() total = 0 @@ -73,6 +74,8 @@ class Result(object): if chunk: f.write(chunk) total += len(chunk) + finally: + r.close() assert total == size |