#4148 Fetch repository metadata using urlopen instead of requests
Opened 7 months ago by taliaferro-llnl. Modified 7 months ago
taliaferro-llnl/koji 4146-urlopen  into  master

file modified
+6 -7
@@ -33,11 +33,11 @@ 

  import traceback

  from optparse import OptionParser, SUPPRESS_HELP

  from xml.etree import ElementTree

+ from urllib.request import urlopen

+ from urllib.error import HTTPError

  

  from collections import OrderedDict

  

- import requests

- 

  import koji

  from koji.util import deprecated, parseStatus, rmtree, to_list, dslice

  
@@ -388,15 +388,14 @@ 

                  continue

              self.logger.debug('Checking external url: %s' % arch_url)

              try:

-                 r = requests.get(arch_url, timeout=5)

-                 r.raise_for_status()

-                 root = ElementTree.fromstring(r.text)  # nosec

+                 response = urlopen(arch_url, None, 5)

+                 root = ElementTree.parse(response)

                  ts_elements = root.iter('{http://linux.duke.edu/metadata/repo}timestamp')

                  arch_ts = max([round(float(child.text)) for child in ts_elements])

                  ts_cache[arch_url] = arch_ts

                  new_ts = max(new_ts, arch_ts)

-             except requests.exceptions.HTTPError as e:

-                 if e.response.status_code == 404:

+             except HTTPError as e:

+                 if e.code == 404:

                      # we check all hub arches, so this can happen pretty easily

                      # we'll warn below if _no_ arches give us a timestamp

                      self.logger.debug("External repo url not found: %s", arch_url)

By switching to urllib instead of Requests for this specific request, kojira can now support upstream repositories accessed by a file:// URL (e.g. local synced copies of the repo shared by NFS.)

Metadata