Skip to content

Commit 962186f

Browse files
committed
FIX: Check status code for from_url
1 parent 5499b28 commit 962186f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pathlib import Path
2+
3+
from nibabel.cifti2.caretspec import *
4+
5+
from nibabel.testing import data_path
6+
7+
8+
def test_CaretSpecFile():
9+
fsLR = CaretSpecFile.from_filename(Path(data_path) / "fsLR.wb.spec")
10+
11+
assert fsLR.metadata == {}
12+
assert fsLR.version == "1.0"
13+
assert len(fsLR.data_files) == 5
14+
15+
for df in fsLR.data_files:
16+
assert isinstance(df, CaretSpecDataFile)
17+
if df.data_file_type == 'SURFACE':
18+
assert isinstance(df, SurfaceDataFile)

nibabel/filebasedimages.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,13 @@ def to_bytes(self, **kwargs):
576576
return bio.getvalue()
577577

578578
@classmethod
579-
def from_url(klass, url):
579+
def from_url(klass, url, timeout=5):
580580
""" Fetch image from remote location and construct an image
581581
582582
Requires the ``requests`` library to be installed.
583583
"""
584584
import requests
585-
res = requests.get(url)
585+
res = requests.get(url, timeout=timeout)
586+
if not res.ok:
587+
raise IOError(f"[Error {res.status_code}] Could not retrieve {url}")
586588
return klass.from_bytes(res.content)

0 commit comments

Comments
 (0)