There was an error while loading. Please reload this page.
1 parent 5c4eeac commit 980c649Copy full SHA for 980c649
3 files changed
lib/matplotlib/image.py
@@ -1468,10 +1468,16 @@ def imread(fname, format=None):
1468
img_open = (
1469
PIL.PngImagePlugin.PngImageFile if ext == 'png' else PIL.Image.open)
1470
if isinstance(fname, str):
1471
+ import io
1472
+ from urllib import request
1473
+
1474
parsed = urllib.parse.urlparse(fname)
1475
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
- from urllib import request
- with urllib.request.urlopen(fname) as response:
1476
+ with request.urlopen(fname) as response:
1477
+ try:
1478
+ response.seek(0)
1479
+ except (AttributeError, io.UnsupportedOperation):
1480
+ response = io.BytesIO(response.read())
1481
return imread(response, format=ext)
1482
with img_open(fname) as image:
1483
return (_pil_png_to_float_array(image)
lib/matplotlib/testing/conftest.py
@@ -16,6 +16,7 @@ def pytest_configure(config):
16
("markers", "style: Set alternate Matplotlib style temporarily."),
17
("markers", "baseline_images: Compare output against references."),
18
("markers", "pytz: Tests that require pytz to be installed."),
19
+ ("markers", "network: Tests that reachout to the network."),
20
("filterwarnings", "error"),
21
]:
22
config.addinivalue_line(key, value)
lib/matplotlib/tests/test_image.py
@@ -1118,3 +1118,9 @@ def test_exact_vmin():
1118
1119
# check than the RBGA values are the same
1120
assert np.all(from_image == direct_computation)
1121
1122
1123
+@pytest.mark.network
1124
+@pytest.mark.flaky
1125
+def test_https_imread_smoketest():
1126
+ v = mimage.imread('https://matplotlib.org/1.5.0/_static/logo2.png')
0 commit comments