Add workaround for old requests in kojiwrapper

When running with requests<2.18 (i.e. on RHEL 7), streaming responses
are not a context manager and need to be wrapped in contextlib.closing.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
(cherry picked from commit 860360629d)
This commit is contained in:
Lubomír Sedlář 2024-01-19 10:32:26 +01:00 committed by Stepan Oksanichenko
parent 34fcd550b6
commit 27d055992e
Signed by: soksanichenko
GPG Key ID: AB9983172AB1E45B

View File

@ -999,7 +999,8 @@ class KojiDownloadProxy:
:param str dest: file path to store the result in :param str dest: file path to store the result in
:returns: path to the downloaded file (same as dest) or None if the URL :returns: path to the downloaded file (same as dest) or None if the URL
""" """
with self.session.get(url, stream=True) as r: # contextlib.closing is only needed in requests<2.18
with contextlib.closing(self.session.get(url, stream=True)) as r:
if r.status_code == 404: if r.status_code == 404:
self.logger.warning("GET %s NOT FOUND", url) self.logger.warning("GET %s NOT FOUND", url)
return None return None