rstudio / pins-r

Pin, discover, and share resources
https://pins.rstudio.com
Other
312 stars 63 forks source link

Error while reading pin metadata on RStudio Connect #469

Closed juliasilge closed 3 years ago

juliasilge commented 3 years ago

I am using the current dev version of the package and can use pin_write() and pin_list() just fine, but am having trouble with pin_read() because this line in pin_meta.pins_board_rsconnect gives a 404:

https://github.com/rstudio/pins/blob/322b3df464202ef3a4726cded3f1a549cefef11c/R/board_rsconnect.R#L249

library(pins)

b <- board_rsconnect("envvar")
b %>% pin_read("julia.silge/biv_svm")
#> Error in rsc_check_status(req): Not Found (HTTP 404).

Created on 2021-06-23 by the reprex package (v2.0.0)

This happens for all pins I try to read. If I try to read again, I get a different error because data.txt has been saved with HTML in it.

<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.0 (Ubuntu)</center>
</body>
</html>
andrie commented 3 years ago

The root cause is that the function board_rsconnect() constructs the server URL from hostname + __api__. However, this ignores the fact that the full domain name can contain hostname + path + __api__.

For example, if the real server is at colorado.rstudio.com/rsc, then the API endpoint is at colorado.rstudio.com/rsc/__api__, but the current code base ignores the /rsc path.

One solution to this is to use rsconnect::serverInfo() to construct the URL, like this:

url <- rsconnect::serverInfo(name = server)$url

instead of the current:

url <- paste0(server, "/__api__/") # remember to delete this line

I'll prepare a PR.

github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.