diff --git a/src/machinevisiontoolbox/Sources.py b/src/machinevisiontoolbox/Sources.py index efe1366a..7b3cb74a 100644 --- a/src/machinevisiontoolbox/Sources.py +++ b/src/machinevisiontoolbox/Sources.py @@ -4137,17 +4137,14 @@ class reads the JSON file and extracts the image, polygonal shapes, and associat def __init__(self, filename: str) -> None: self.filename = filename - try: - if str(filename).startswith(("http://", "https://")): - import urllib.request + if str(filename).startswith(("http://", "https://")): + import urllib.request - with urllib.request.urlopen(filename) as response: # noqa: S310 - self.data = json.loads(response.read().decode("utf-8")) - else: - with open(self.filename, "r", encoding="utf-8") as f: - self.data = json.load(f) - except (OSError, json.JSONDecodeError, TypeError, ValueError): - return None + with urllib.request.urlopen(filename) as response: # noqa: S310 + self.data = json.loads(response.read().decode("utf-8")) + else: + with open(self.filename, "r", encoding="utf-8") as f: + self.data = json.load(f) self._nshapes = len(self.data.get("shapes", [])) self._version = self.data.get("version")