Skip to content

Commit 9cf669b

Browse files
committed
don't try to read magic numbers for remote uris
1 parent 017713b commit 9cf669b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

xarray/backends/h5netcdf_.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,16 @@ class H5netcdfBackendEntrypoint(BackendEntrypoint):
462462
supports_groups = True
463463

464464
def guess_can_open(self, filename_or_obj: T_PathFileOrDataStore) -> bool:
465+
from xarray.core.utils import is_remote_uri
466+
465467
filename_or_obj = _normalize_filename_or_obj(filename_or_obj)
466-
magic_number = try_read_magic_number_from_file_or_path(filename_or_obj)
467-
if magic_number is not None:
468-
return magic_number.startswith(b"\211HDF\r\n\032\n")
468+
469+
# Try to read magic number for local files only
470+
is_remote = isinstance(filename_or_obj, str) and is_remote_uri(filename_or_obj)
471+
if not is_remote:
472+
magic_number = try_read_magic_number_from_file_or_path(filename_or_obj)
473+
if magic_number is not None:
474+
return magic_number.startswith(b"\211HDF\r\n\032\n")
469475

470476
if isinstance(filename_or_obj, str | os.PathLike):
471477
_, ext = os.path.splitext(str(filename_or_obj))

0 commit comments

Comments
 (0)