Skip to content

Commit 55ba612

Browse files
tacaswelltimhoffm
andauthored
MNT: Be more defensive about pre-reading into BytesIO
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
1 parent 66ff15a commit 55ba612

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/matplotlib/image.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,11 @@ def imread(fname, format=None):
14731473
parsed = urllib.parse.urlparse(fname)
14741474
if len(parsed.scheme) > 1: # Pillow doesn't handle URLs directly.
14751475
with urllib.request.urlopen(fname) as response:
1476-
return imread(BytesIO(response.read()), format=ext)
1476+
try:
1477+
response.seek(0)
1478+
except (AttributeError, io.UnsupportedOperation):
1479+
response = BytesIO(response.read())
1480+
return imread(response, format=ext)
14771481
with img_open(fname) as image:
14781482
return (_pil_png_to_float_array(image)
14791483
if isinstance(image, PIL.PngImagePlugin.PngImageFile) else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy