From a49e8ce7837db4fd92d6ab8ba491deb7154d4b5e Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Fri, 22 Jun 2018 15:31:14 +0200 Subject: Do not depend on the Request object being a context manager (introduced in requests >= 2.18.0) --- cdsapi/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'cdsapi') 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 -- cgit v1.2.3