Page 1 of 1

401 Authentication Issue, Connecting to NLDAS with R's GET

Posted: Thu Jan 30, 2025 1:28 pm America/New_York
by rishi.kowalski
Hi,

I'm attempting to connect to the NLDAS Forcing dataset via GrADS server ASCII calls, generated in R and called through R's GET() function via the HTTR package. I've generated a series of URLs that seem to work when pasted into my browser (with username/password authentication via prompt), however when I try to pull the data in R, I run into a Status 401, Access Denied error. Any advice on authentication via R would be appreciated, as I've used GET with user/password authorization in the past with no issues (see method 1). I've tried a couple different ways, including specifying my token in the header (token generated today); see examples below:

url <- "https://hydro1.gesdisc.eosdis.nasa.gov/dods/NLDAS_FORA0125_H.2.0.ascii?wind_e[271739:276739][33][354]"
Method 1: GET(url, authenticate(key_get("nldas-credential-user"), key_get("nldas-credential-pass")))
Method 2: GET(url, authenticate(key_get("nldas-credential-user"), key_get("nldas-credential-pass")), add_headers(paste("Authorization: Bearer", my-token)))

Relevant Information:
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 15.2
Packages:
keyring_1.3.2
jsonlite_1.8.9
httr_1.4.7
curl_6.1.0

Re: 401 Authentication Issue, Connecting to NLDAS with R's GET

Posted: Tue Feb 04, 2025 11:33 am America/New_York
by GES DISC - jimacker
Hello, I apologize for our slow response. We are examining your query now.

Re: 401 Authentication Issue, Connecting to NLDAS with R's GET

Posted: Tue Feb 04, 2025 11:51 am America/New_York
by rishi.kowalski
Hi,

Thanks for the reply - I actually ended up resolving this issue by following the instructions here to associate my .netrc file with the query (https://urs.earthdata.nasa.gov/documentation/for_users/data_access/r) and my queries are working now. I'm not sure how or why they were working previously without the .netrc file however!

Thanks again!

Re: 401 Authentication Issue, Connecting to NLDAS with R's GET

Posted: Tue Feb 04, 2025 2:57 pm America/New_York
by GES DISC - jimacker
Excellent. I am glad that the instructions were both useful and correct.