Accessing data on THREDDS OpenDAP via python (netcdf4 or xarray): Dealing with _FillValue type mismatch error

If you try to access OOI data via OpenDAP, you may encounter the following error:

NetCDF: Not a valid data type or _FillValue type mismatch

This is due to a bug in THREDDS that will be fixed in a future release.

In the meantime, you can work around this issue simply by appending #fillmismatch to the end of your url.

Here’s a code snippet to illustrate this issue and the workaround:

import netCDF4 as nc
import xarray as xr

url = ''

# Running either of the commands below results in an error:
#   OSError: [Errno -45] NetCDF: Not a valid data type or _FillValue type mismatch

# Running either of these commands will open the file successfully
url_with_fillmismatch = f'{url}#fillmismatch'
ds = xr.open_dataset(url_with_fillmismatch)
with nc.Dataset(url_with_fillmismatch) as nc_ds: