Get data from OpenDap server that requires authentication using R

半世苍凉 提交于 2019-12-11 15:19:22

问题


I'm trying to get data from an OPeNDAP server using R and the ncdf4 package. However, the nasa eosdis server requires username / password. How can I pass this info using R?

Here is what I'm trying to do:

require(ncdf4)
f1 <- nc_open('https://disc2.gesdisc.eosdis.nasa.gov/opendap/TRMM_L3/TRMM_3B42.7/2018/020/3B42.20180120.15.7.HDF')

And the error message:

Error in Rsx_nc4_get_vara_double: NetCDF: Authorization failure syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: HTTP^ Basic: Access denied. Var: nlat Ndims: 1
Start: 0 Count: 400 Error in ncvar_get_inner(d$dimvarid$group_id, d$dimvarid$id, default_missval_ncdf4(), : C function R_nc4_get_vara_double returned error

I tried the url https://username:password@disc2.... but that did not work also.


回答1:


Daniel,

The service you are accessing is using third-party redirection to authenticate users. Therefore the simple way of providing credentials in the URL doesn't work.

You need to create 2 files.

  1. A .dodsrc file (a RC file for the netcdf-c library) with the following content

    HTTP.COOKIEFILE=.cookies
    HTTP.NETRC=.netrc

  2. A .netrc file, in the location referenced in the .dodsrc, with your credentials:

    machine urs.earthdata.nasa.gov
    login YOURUSERNAMEHERE
    password YOURPASWORDHERE

You can find more details at https://www.unidata.ucar.edu/software/netcdf/docs/md__Users_wfisher_Desktop_v4_86_81-prep_netcdf-c_docs_auth.html

Regards

Antonio



来源:https://stackoverflow.com/questions/52098781/get-data-from-opendap-server-that-requires-authentication-using-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!