failing to send authenticate to opendap url

0 views
Skip to first unread message

Folkes, Michael (DFO/MPO)

unread,
May 5, 2026, 4:32:58 PM (9 days ago) May 5
to sup...@opendap.org

Unclassified - Non-Classifié


Hello,

I’ve been using some R code to annually query opendap for several years.  It worked fine this time last year but I think my problem might be with sending my authentication.

 

I know my url is fine as if I paste it:

https://opendap.earthdata.nasa.gov/collections/C2098858642-POCLOUD/granules/oscar_currents_final_20220101.dap.nc4?dap4.ce=/lon%5B720:1:960%5D;/time%5B0:1:0%5D;/u%5B0:1:0%5D%5B720:1:960%5D%5B519:1:599%5D;/lat%5B519:1:599%5D;/v%5B0:1:0%5D%5B720:1:960%5D%5B519:1:599%5D

 

to the dap4 data request form:

https://opendap.earthdata.nasa.gov/collections/C2098858642-POCLOUD/granules/oscar_currents_final_20220101.dmr.html

(after logging in), it produces the expected data.

 

 

However, sending the same request via R:

httr::GET(url, httr::authenticate(opendap_authenticate$id,opendap_authenticate$pw),httr::write_disk(path = "oscar_currents_final_20220101.nc" , overwrite = TRUE))

 

is producing a “status 401” result.   The ID and PW I send are the same I used to log into the dap4 data request form.

Do you have any suggestions as to why my ID and PW might not be giving me access when I attempt this using a call from R? (again, it worked fine last summer).

Thanks!

Michael

Miguel Jimenez

unread,
May 6, 2026, 2:31:28 PM (8 days ago) May 6
to sup...@opendap.org
Hi Michael, 

That sounds frustrating. I am very versed in R, but I tried it in python and had no trouble downloading data from that granule. Here is my snippet of code, which uses python's requests session to authenticate

```python
from requests import Session

my_session = Session()

r = my_session.get(url, stream=True)
r.status_code
>>> 200 # <-------- success!
```

NOTE: Python's requests session can discover /recover all the authentication credentials stored in a local `.netrc` file so there is no need to pass these all the time. I know in R one can do that, but it may require configuring R to use curl which is pretty good and efficient. But again, I am not very well versed on that.

That said, I do not know what changed in the year that you have tried it. I know EDL requires updating token credentials every few months (tokens expire in a few months that is), but it looks like you are using username/password and not tokens (unless you have something configured running in the background).

I would suggest looking into configuring R to use .netrc files. THese have pretty strong support and can be used with edl tokens (faster performance, but may require updating the .netrc file every couple of months).


Hope this helps, and let me know how it goes!

Miguel
Reply all
Reply to author
Forward
0 new messages