summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cdsapi/api.py5
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