From 2f95fc9ff11d9d937d860f80703b3cbb1199a8f8 Mon Sep 17 00:00:00 2001 From: Yuming Zhu Date: Dec 04 2019 09:53:06 +0000 Subject: do not use with statement with requests.get fixes: #1530 --- diff --git a/koji/__init__.py b/koji/__init__.py index 6acd1bb..039aecc 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -1675,9 +1675,12 @@ def openRemoteFile(relpath, topurl=None, topdir=None, tempdir=None): if topurl: url = "%s/%s" % (topurl, relpath) fo = tempfile.TemporaryFile(dir=tempdir) - with requests.get(url) as resp: + try: + resp = requests.get(url) for chunk in resp.iter_content(chunk_size=8192): fo.write(chunk) + finally: + resp.close() fo.seek(0) elif topdir: fn = "%s/%s" % (topdir, relpath) diff --git a/koji/tasks.py b/koji/tasks.py index 5c7d0bd..4e649ec 100644 --- a/koji/tasks.py +++ b/koji/tasks.py @@ -479,12 +479,15 @@ class BaseTaskHandler(object): return fn self.logger.debug("Downloading %s", relpath) url = "%s/%s" % (self.options.topurl, relpath) - with requests.get(url) as resp: + try: + resp = requests.get(url) if not os.path.exists(os.path.dirname(fn)): os.makedirs(os.path.dirname(fn)) with open(fn, 'wb') as fdst: for chunk in resp.iter_content(chunk_size=8192): fdst.write(chunk) + finally: + resp.close() else: fn = "%s/%s" % (self.options.topdir, relpath) return fn