ropensci / EDIutils

An API Client for the Environmental Data Initiative Repository
https://docs.ropensci.org/EDIutils/
Other
10 stars 2 forks source link

api_update_data_package() returning 401 after successful PUT #20

Closed ianbrunjes closed 2 years ago

ianbrunjes commented 3 years ago

I am calling EDIutils::api_update_data_package() in an R script to update a data package.

The response from the function call is an HTTP error 401, but the PUT to update the datapackage is successful, and I can view the package with its new doi. The error seems to come from the logic after a successful PUT- line 93, api_update_data_package.R

> new_doi
[1] "edi.416.6"
> EDIutils::api_update_data_package(
+     path = eml_path,
+     package.id = new_doi,
+     environment = "staging",
+     user.id = usern,
+     user.pass = passw,
+     affiliation = "EDI"
+ )
Error in open.connection(con, "rb") : HTTP error 401.
> traceback()
7: open.connection(con, "rb")
6: open(con, "rb")
5: read_connection(path)
4: datasource_connection(file, skip, skip_empty_rows, comment, skip_quote)
3: datasource(file, skip_empty_rows = FALSE)
2: readr::read_file(paste0(url_env(environment), ".lternet.edu/package/report/eml/", 
       stringr::str_replace_all(package.id, "\\.", "/")))
1: EDIutils::api_update_data_package(path = eml_path, package.id = new_doi, 
       environment = "staging", user.id = usern, user.pass = passw, 
       affiliation = "EDI")
> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
ianbrunjes commented 3 years ago

Since the PUT is successful, we can assume that the auth credentials are being correctly provided. Here is the successfully updated dataset: https://portal-s.edirepository.org/nis/metadataviewer?packageid=edi.416.6

clnsmth commented 3 years ago

Thanks for reporting this issue this helpful report @BrennieDev! It looks like I'll have to refactor access to the evaluation report (line 93), which is restricted to only authenticated users in the case of your data package (i.e. public doesn't have read access).

clnsmth commented 2 years ago

This issue is fixed on the main branch