diff --git a/Changelog.rst b/Changelog.rst index 92eaf67731..ddb3c27e79 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -1,7 +1,7 @@ version 3.15.4 -------------- -**2023-??-??** +**2023-10-??** * Record dimension coordinate cell characteristics (https://github.com/NCAS-CMS/cf-python/issues/692) @@ -10,6 +10,10 @@ version 3.15.4 1-d constructs whose axis is not in the data, even when the criterion was not matched (https://github.com/NCAS-CMS/cf-python/issues/691) +* Fix bug that prevented "https://" netCDF files from being read + (https://github.com/NCAS-CMS/cf-python/issues/699) + +---- version 3.15.3 -------------- diff --git a/cf/read_write/read.py b/cf/read_write/read.py index 02893a4c79..7d8a9da547 100644 --- a/cf/read_write/read.py +++ b/cf/read_write/read.py @@ -5,6 +5,7 @@ from numbers import Integral from os.path import isdir from re import Pattern +from urllib.parse import urlparse from cfdm import is_log_level_info from numpy.ma.core import MaskError @@ -883,7 +884,8 @@ def read( # Expand variables file_glob = os.path.expanduser(os.path.expandvars(file_glob)) - if file_glob.startswith("http://"): + scheme = urlparse(file_glob).scheme + if scheme in ("https", "http"): # Do not glob a URL files2 = (file_glob,) else: diff --git a/cf/test/test_read_write.py b/cf/test/test_read_write.py index 0720ef4173..71340069bd 100644 --- a/cf/test/test_read_write.py +++ b/cf/test/test_read_write.py @@ -917,6 +917,14 @@ def test_write_omit_data(self): self.assertFalse(g.array.count()) self.assertTrue(g.construct("grid_latitude").array.count()) + def test_read_url(self): + """Test reading urls.""" + for scheme in ("http", "https"): + remote = f"{scheme}://psl.noaa.gov/thredds/dodsC/Datasets/cru/crutem5/Monthlies/air.mon.anom.nobs.nc" + # Check that cf can access it + f = cf.read(remote) + self.assertEqual(len(f), 1) + if __name__ == "__main__": print("Run date:", datetime.datetime.now())