From e4187734bd8d7be363666eda5d268626679e549c Mon Sep 17 00:00:00 2001 From: Arnie97 Date: Tue, 26 Apr 2022 14:09:44 +0800 Subject: [PATCH] Fix cert verify failed --- source/repomd.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/repomd.py b/source/repomd.py index 18503fb..223358d 100644 --- a/source/repomd.py +++ b/source/repomd.py @@ -6,6 +6,13 @@ import urllib.request import urllib.parse +try: + import ssl + import certifi + ssl_context = ssl.create_default_context(cafile=certifi.where()) +except ImportError: + ssl_context = None + _ns = { 'common': 'http://linux.duke.edu/metadata/common', @@ -24,7 +31,7 @@ def load(baseurl): repomd_url = base._replace(path=str(repomd_path)).geturl() # download and parse repomd.xml - with urllib.request.urlopen(repomd_url) as response: + with urllib.request.urlopen(repomd_url, context=ssl_context) as response: repomd_xml = defusedxml.lxml.fromstring(response.read()) # determine the location of *primary.xml.gz @@ -33,7 +40,7 @@ def load(baseurl): primary_url = base._replace(path=str(primary_path)).geturl() # download and parse *-primary.xml - with urllib.request.urlopen(primary_url) as response: + with urllib.request.urlopen(primary_url, context=ssl_context) as response: with io.BytesIO(response.read()) as compressed: with gzip.GzipFile(fileobj=compressed) as uncompressed: metadata = defusedxml.lxml.fromstring(uncompressed.read())