Skip to content

Commit add2fc0

Browse files
committed
FIX: Check status code for from_url
1 parent 9c4031d commit add2fc0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
Lines changed: 18 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,13 @@ def to_bytes(self):
573573
return bio.getvalue()
574574

575575
@classmethod
576-
def from_url(klass, url):
576+
def from_url(klass, url, timeout=5):
577577
""" Fetch image from remote location and construct an image
578578
579579
Requires the ``requests`` library to be installed.
580580
"""
581581
import requests
582-
res = requests.get(url)
582+
res = requests.get(url, timeout=timeout)
583+
if not res.ok:
584+
raise IOError(f"[Error {res.status_code}] Could not retrieve {url}")
583585
return klass.from_bytes(res.content)

0 commit comments

Comments
 (0)