Skip to content

Commit 972cdaa

Browse files
authored
Merge pull request NCAS-CMS#700 from davidhassell/https-fix
Fix bug that prevented `https://` netCDF files from being read
2 parents 2cfc8e6 + b31291e commit 972cdaa

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Changelog.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version 3.15.4
22
--------------
33

4-
**2023-??-??**
4+
**2023-10-??**
55

66
* Record dimension coordinate cell characteristics
77
(https://github.com/NCAS-CMS/cf-python/issues/692)
@@ -10,6 +10,10 @@ version 3.15.4
1010
1-d constructs whose axis is not in the data, even when the
1111
criterion was not matched
1212
(https://github.com/NCAS-CMS/cf-python/issues/691)
13+
* Fix bug that prevented "https://" netCDF files from being read
14+
(https://github.com/NCAS-CMS/cf-python/issues/699)
15+
16+
----
1317

1418
version 3.15.3
1519
--------------

cf/read_write/read.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from numbers import Integral
66
from os.path import isdir
77
from re import Pattern
8+
from urllib.parse import urlparse
89

910
from cfdm import is_log_level_info
1011
from numpy.ma.core import MaskError
@@ -883,7 +884,8 @@ def read(
883884
# Expand variables
884885
file_glob = os.path.expanduser(os.path.expandvars(file_glob))
885886

886-
if file_glob.startswith("http://"):
887+
scheme = urlparse(file_glob).scheme
888+
if scheme in ("https", "http"):
887889
# Do not glob a URL
888890
files2 = (file_glob,)
889891
else:

cf/test/test_read_write.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,14 @@ def test_write_omit_data(self):
917917
self.assertFalse(g.array.count())
918918
self.assertTrue(g.construct("grid_latitude").array.count())
919919

920+
def test_read_url(self):
921+
"""Test reading urls."""
922+
for scheme in ("http", "https"):
923+
remote = f"{scheme}://psl.noaa.gov/thredds/dodsC/Datasets/cru/crutem5/Monthlies/air.mon.anom.nobs.nc"
924+
# Check that cf can access it
925+
f = cf.read(remote)
926+
self.assertEqual(len(f), 1)
927+
920928

921929
if __name__ == "__main__":
922930
print("Run date:", datetime.datetime.now())

0 commit comments

Comments
 (0)