diff --git a/apport/packaging_impl/apt_dpkg.py b/apport/packaging_impl/apt_dpkg.py index 10c189db3..1042b5f6e 100644 --- a/apport/packaging_impl/apt_dpkg.py +++ b/apport/packaging_impl/apt_dpkg.py @@ -28,7 +28,6 @@ import glob import gzip import hashlib -import http.client import json import logging import os @@ -933,10 +932,6 @@ def get_source_tree( return None sf_urls = self.get_lp_source_package(srcpackage, version) if sf_urls: - proxy = "" - if apt_pkg.config.find("Acquire::http::Proxy") != "": - proxy = apt_pkg.config.find("Acquire::http::Proxy") - apt_pkg.config.set("Acquire::http::Proxy", "") fetch_progress = apt.progress.base.AcquireProgress() fetcher = apt_pkg.Acquire(fetch_progress) af_queue = [] @@ -950,8 +945,6 @@ def get_source_tree( result = fetcher.run() if result != fetcher.RESULT_CONTINUE: return None - if proxy: - apt_pkg.config.set("Acquire::http::Proxy", proxy) for dsc in glob.glob(os.path.join(output_dir, "*.dsc")): subprocess.call( ["dpkg-source", "-sn", "-x", dsc], @@ -1184,9 +1177,6 @@ def install_packages( apt_pkg.config.clear("APT::Architectures") apt_pkg.config.set("APT::Architectures::", architecture) apt_pkg.config.set("Acquire::Languages", "none") - # directly connect to Launchpad when downloading deb files - apt_pkg.config.set("Acquire::http::Proxy::api.launchpad.net", "DIRECT") - apt_pkg.config.set("Acquire::http::Proxy::launchpad.net", "DIRECT") if not verbose: fetch_progress = apt.progress.base.AcquireProgress() @@ -1625,22 +1615,19 @@ def _fetch_contents_file( """Returns True on success (including when no update is needed).""" url = f"{self._get_mirror(arch)}/dists/{dist}/Contents-{arch}.gz" if mtime: - # HTTPConnection requires server name e.g. - # archive.ubuntu.com - server = urllib.parse.urlparse(url)[1] - conn = http.client.HTTPConnection(server) - conn.request("HEAD", urllib.parse.urlparse(url)[2]) - res = conn.getresponse() - modified_str = res.getheader("last-modified", None) - if modified_str: - modified = datetime.datetime.strptime( - modified_str, "%a, %d %b %Y %H:%M:%S %Z" - ) - if modified <= datetime.datetime.fromtimestamp(mtime): + req = urllib.request.Request(url, method="HEAD") + with contextlib.suppress(OSError): + with urllib.request.urlopen(req) as res: + modified_str = res.getheader("last-modified", None) + if modified_str: + modified = datetime.datetime.strptime( + modified_str, "%a, %d %b %Y %H:%M:%S %Z" + ) + if modified <= datetime.datetime.fromtimestamp(mtime): + return True + # don't update the file if it is empty + if res.getheader("content-length", None) == "40": return True - # don't update the file if it is empty - if res.getheader("content-length", None) == "40": - return True self._contents_update = True try: