Repository navigation
Description
Hi,
I'm using netcdf4-python (1.5.1.2) on a Mac (OS 10.14.4), with netcdf4 installed via brew with dap2 support:
$ nc-config --has-dap2 --version
yes
netCDF 4.6.2
I'm trying to access files via OpenDAP on CEDA (https://data.ceda.ac.uk), which require registration. I've used their instructions to generate a certificate:
I have then set up a .dodsrc file pointing to the certificate and the trust roots.
HTTP.COOKIEJAR=./dods_cookies
HTTP.SSL.CERTIFICATE=./credentials.pem
HTTP.SSL.KEY=./credentials.pem
HTTP.SSL.CAPATH=./ca-trustroots
If I now try and access a file from within python then I get an I/O error:
In [1]: import netCDF4
...: ds = netCDF4.Dataset('http://dap.ceda.ac.uk/thredds/dodsC/badc/cmip5/data/cmip5/output1/ICHEC/EC-EARTH/rcp85/day/atmos/day/r12i1p1/latest/tas/tas_day_EC-EARTH_rcp85_r12i1p1_20560101-21001231.nc')
...:
...: ds.variables.keys()
...:
curl error details:
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-1-1de901bc5de0> in <module>()
1 import netCDF4
----> 2 ds = netCDF4.Dataset('http://dap.ceda.ac.uk/thredds/dodsC/badc/cmip5/data/cmip5/output1/ICHEC/EC-EARTH/rcp85/day/atmos/day/r12i1p1/latest/tas/tas_day_EC-EARTH_rcp85_r12i1p1_20560101-21001231.nc')
3
4 ds.variables.keys()
netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__()
netCDF4/_netCDF4.pyx in netCDF4._netCDF4._ensure_nc_success()
IOError: [Errno -68] NetCDF: I/O failure: 'http://dap.ceda.ac.uk/thredds/dodsC/badc/cmip5/data/cmip5/output1/ICHEC/EC-EARTH/rcp85/day/atmos/day/r12i1p1/latest/tas/tas_day_EC-EARTH_rcp85_r12i1p1_20560101-21001231.nc'
However, if I run the same path with ncdump, then I get a successful connection, the data is downloaded and the dods_cookies file is populated with session tokens. After this, netCDF4-python works fine. That makes it seem like netCDF4-python knows about the .dodsrc file and can use the session cookies that it points to but can't currently generate those cookies. Or alternatively, there is a setup step I'm missing in Python.
Cheers,
David
Activity
jswhit commentedon Jun 25, 2019
I'm pretty sure that netcdf4-python goes through the same code path in the C library as the ncdump utility does. Are you sure that netcdf4-python is built with the same version of netcdf-c as the ncdump you are using?
@DennisHeimbigner, do you have any thoughts on this?
rsmith013 commentedon Jun 25, 2019
I have been having the same problem.
netcdf4 installed with
conda install -c anaconda netcdf4uses version 13 of the C library.When installed with pip, the latest version 1.5.1.2 uses v 16 of the C lib.
I have come up against this issue when using the pip installed netcdf library but it seems to work as expected when installed with conda.
davidorme commentedon Jun 25, 2019
OK, so netcdf4-python is using its own version of netcdf4-c:
If I look at the open files used by the Python process, it seems to be using the package version at
/usr/local/lib/python2.7/site-packages/netCDF4/.dylibs/libnetcdf.15.dylib. I only know how to check the config using nc-config but I assume that the pip binaries support OpenDAP because libcurl is also in that folder and being linked by Python.I could install from source so it uses my brew installed libs, but it seems like it should still work even if there are two different versions of the netcdf-c library?
jswhit commentedon Jun 25, 2019
Could be that the netcdf-c library is configured and built differently in the Ubuntu package used by travis to build the binary wheels used by pip. Maybe the curl/openssl support is disabled, or different.
Or, is it actually using the netcdf library installed via homebrew? Maybe there is an issue with the openssl support in the homebrew curl library?
davidorme commentedon Jun 25, 2019
I can rule out (I think!) some of that:
If I use
ncdump(which is installed by brew) then I can access the CEDA OpenDAP files:ncdumpsuccessfully uses.dodsrcand the tags in it to negotiate session tokens and then fetches data. So I think the brew installation is working as expected.I don't think curl/openssl can be disabled in the pip wheels because once the dods_cookies file exists via
ncdump, then netCDF4-python accesses the files perfectly happily. I did wonder if it might be a path issue - my.dodsrcfile and the certs are in a local folder not $HOME, but again, once the dods_cookies exist then netCDF4-python uses them. I guess that leaves different.jswhit commentedon Jun 25, 2019
You can use 'otool -L' on the ncdump executable and the _netCDF4.so shared object to see if they are using different versions of the curl and/or netcdf libs.
davidorme commentedon Jun 25, 2019
Which gives:
and
To me, that looks like the netCDF4-python binary wheel isn't using libcurl, although it is present in the package
.dylibsdirectory, but that doesn't seem to square with netCDF4-python working when the cookies are present?$ ls -lah /usr/local/lib/python2.7/site-packages/netCDF4/.dylibs total 35088 drwxr-xr-x 8 dorme admin 256B 21 Jun 15:36 . drwxr-xr-x 8 dorme admin 256B 21 Jun 15:36 .. -rw-r--r-- 1 dorme admin 75K 21 Jun 15:36 libaec.0.dylib -rw-r--r-- 1 dorme admin 688K 21 Jun 15:36 libcurl.4.dylib -rw-r--r-- 1 dorme admin 13M 21 Jun 15:36 libhdf5.101.dylib -rw-r--r-- 1 dorme admin 358K 21 Jun 15:36 libhdf5_hl.100.dylib -rw-r--r-- 1 dorme admin 3.0M 21 Jun 15:36 libnetcdf.15.dylib -rw-r--r-- 1 dorme admin 33K 21 Jun 15:36 libsz.2.dylibjswhit commentedon Jun 25, 2019
How about 'otool -L /usr/local/lib/python2.7/site-packages/netCDF4/.dylibs/libnetcdf.15.dylib'?
DennisHeimbigner commentedon Jun 25, 2019
You might re-review
https://github.com/Unidata/netcdf-c/blob/master/docs/auth.md#REDIR
to ensure that the python tests are following all the steps, especially
for redirection.
This note from that document should be verified:
davidorme commentedon Jun 25, 2019
Oh, okay.
_netCDF4.solinkslibnetcdf.15.dyliband that linkslibcurl.jswhit commentedon Jun 25, 2019
That's what I thought. The next question is does libcurl link openssl? It looks like maybe it uses the MacOSX security framework instead.
davidorme commentedon Jun 25, 2019
Looks like it:
davidorme commentedon Jun 25, 2019
Hi @DennisHeimbigner,
I've tried playing around with the
dods_cookiesfile specified in.dodsrc. If it doesn't exist, then attempting an OpenDAP connection with netCDF4-python does create an empty file with that name, but does not / is not able to populate it with the session cookies and tokens.DennisHeimbigner commentedon Jun 25, 2019
If you pre-create dods_cookies with the correct permissions, I assume it works, correct?
DennisHeimbigner commentedon Jun 25, 2019
I think we encountered this problem before where on OSX,where
we needed to use the osx replacements for openssl. Since we (unidata)
do not regularly test authorization, we might not have checked this any time
recently. The curl website probably needs to be examined to see what it
says about this problem.
DennisHeimbigner commentedon Jun 25, 2019
BTW, when this is solved, It would help if someone provided a concise
description of the fix so I can add it to our (netcdf-c) documentation
to help others with this problem.
davidorme commentedon Jun 26, 2019
@DennisHeimbigner: That's correct. Because I've got the parallel installation of netCDF4-c and the command line tools via brew,
ncdumpcorrectly creates the dods_cookies file and, once it is there, netCDF4-python uses it and works nicely.jswhit commentedon Jun 26, 2019
I bet the libcurl used by the netcdf-c library installed by homebrew uses a homebrew-built openssl, not the MacOSX security framework.
davidorme commentedon Jun 26, 2019
That's not clear (to me). otool shows that
ncdumplinks the/usr/local/lib/libnetcdf.dylib(as you'd expect). Like all (?) homebrew installations, that is a symlink to resources within/usr/local/Cellar:lb-dormelap:Downloads dorme$ ls -lah /usr/local/lib/libnetcdf.dylib lrwxr-xr-x 1 dorme admin 42B 4 Mar 16:23 /usr/local/lib/libnetcdf.dylib -> ../Cellar/netcdf/4.6.2/lib/libnetcdf.dylibHowever,
libnetcdf.dyliblinks/usr/lib/libcurland then that links/usr/lib/libssland neither of these are symlinked to/usr/local/Cellar. I know that the SIP protection on Mac includes/usr/liband I didn't think homebrew used it, but I could be wrong.jswhit commentedon Jun 26, 2019
@matthew-brett - the diagnosis here suggests that the libcurl build for macos x should not use
--with-darwinssl