Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 363108e

Browse filesBrowse files
authored
Merge pull request #18670 from tacaswell/optional_cerifi
MNT: make certifi actually optional
2 parents e5a6008 + 1883380 commit 363108e
Copy full SHA for 363108e

File tree

Expand file treeCollapse file tree

2 files changed

+17
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-4
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,11 @@ def is_url(filename):
717717

718718
@functools.lru_cache()
719719
def _get_ssl_context():
720-
import certifi
720+
try:
721+
import certifi
722+
except ImportError:
723+
_log.debug("Could not import certifi.")
724+
return None
721725
import ssl
722726
return ssl.create_default_context(cafile=certifi.where())
723727

@@ -726,7 +730,12 @@ def _get_ssl_context():
726730
def _open_file_or_url(fname):
727731
if not isinstance(fname, Path) and is_url(fname):
728732
import urllib.request
729-
with urllib.request.urlopen(fname, context=_get_ssl_context()) as f:
733+
ssl_ctx = _get_ssl_context()
734+
if ssl_ctx is None:
735+
_log.debug(
736+
"Could not get certifi ssl context, https may not work."
737+
)
738+
with urllib.request.urlopen(fname, context=ssl_ctx) as f:
730739
yield (line.decode('utf-8') for line in f)
731740
else:
732741
fname = os.path.expanduser(fname)

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,8 +1474,12 @@ def imread(fname, format=None):
14741474
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
14751475
# hide imports to speed initial import on systems with slow linkers
14761476
from urllib import request
1477-
with request.urlopen(fname,
1478-
context=mpl._get_ssl_context()) as response:
1477+
ssl_ctx = mpl._get_ssl_context()
1478+
if ssl_ctx is None:
1479+
_log.debug(
1480+
"Could not get certifi ssl context, https may not work."
1481+
)
1482+
with request.urlopen(fname, context=ssl_ctx) as response:
14791483
import io
14801484
try:
14811485
response.seek(0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.