Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cert verify failed #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions source/repomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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())
Expand Down