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 d941d33

Browse filesBrowse files
authored
Merge pull request #18676 from meeseeksmachine/auto-backport-of-pr-18670-on-v3.3.x
Backport PR #18670 on branch v3.3.x (MNT: make certifi actually optional)
2 parents 58e9740 + 64f1e53 commit d941d33
Copy full SHA for d941d33

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
@@ -762,7 +762,11 @@ def is_url(filename):
762762

763763
@functools.lru_cache()
764764
def _get_ssl_context():
765-
import certifi
765+
try:
766+
import certifi
767+
except ImportError:
768+
_log.debug("Could not import certifi.")
769+
return None
766770
import ssl
767771
return ssl.create_default_context(cafile=certifi.where())
768772

@@ -771,7 +775,12 @@ def _get_ssl_context():
771775
def _open_file_or_url(fname):
772776
if not isinstance(fname, Path) and is_url(fname):
773777
import urllib.request
774-
with urllib.request.urlopen(fname, context=_get_ssl_context()) as f:
778+
ssl_ctx = _get_ssl_context()
779+
if ssl_ctx is None:
780+
_log.debug(
781+
"Could not get certifi ssl context, https may not work."
782+
)
783+
with urllib.request.urlopen(fname, context=ssl_ctx) as f:
775784
yield (line.decode('utf-8') for line in f)
776785
else:
777786
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
@@ -1481,8 +1481,12 @@ def imread(fname, format=None):
14811481
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
14821482
# hide imports to speed initial import on systems with slow linkers
14831483
from urllib import request
1484-
with request.urlopen(fname,
1485-
context=mpl._get_ssl_context()) as response:
1484+
ssl_ctx = mpl._get_ssl_context()
1485+
if ssl_ctx is None:
1486+
_log.debug(
1487+
"Could not get certifi ssl context, https may not work."
1488+
)
1489+
with request.urlopen(fname, context=ssl_ctx) as response:
14861490
import io
14871491
try:
14881492
response.seek(0)

0 commit comments

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