401 Authentication Issue, Connecting to NLDAS with R's GET
-
- Posts: 5
- Joined: Thu Jan 30, 2025 12:24 pm America/New_York
401 Authentication Issue, Connecting to NLDAS with R's GET
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
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
Filters:
-
- User Services
- Posts: 19
- Joined: Wed Dec 04, 2024 4:05 pm America/New_York
- Been thanked: 1 time
Re: 401 Authentication Issue, Connecting to NLDAS with R's GET
Hello, I apologize for our slow response. We are examining your query now.
-
- Posts: 5
- Joined: Thu Jan 30, 2025 12:24 pm America/New_York
Re: 401 Authentication Issue, Connecting to NLDAS with R's GET
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!
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!
-
- User Services
- Posts: 19
- Joined: Wed Dec 04, 2024 4:05 pm America/New_York
- Been thanked: 1 time
Re: 401 Authentication Issue, Connecting to NLDAS with R's GET
Excellent. I am glad that the instructions were both useful and correct.