do not use with statement with requests.get

fixes: #1530
This commit is contained in:
Yuming Zhu 2019-12-04 17:53:02 +08:00 committed by Tomas Kopecek
parent 0e93209587
commit 666111575b
2 changed files with 8 additions and 2 deletions

View file

@ -478,12 +478,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