rdrop2 icon indicating copy to clipboard operation
rdrop2 copied to clipboard

Error in drop_download: Conflict (HTTP 409)

Open JoseBartolomei opened this issue 7 years ago • 9 comments

Hi,

I had a working shiny app using rdrop2 for sometime. When I tried to use it today the app did not retrieved the files that are within DropBox.

Back to R to study what happened I found that that drop_get is deprecated and that I received now the following error:

Downloading: 94 B     Warning: Error in drop_download: Conflict (HTTP 409).
Stack trace (innermost first):
    63: <Anonymous>
    62: stop
    61: httr::stop_for_status
    60: drop_download
    59: eval [/My/DropBox/File/Path/app.R#404]
    58: eval
    57: withProgress
    56: observerFunc [/My/DropBox/File/Path//app.R#399]
     1: runApp

I changed drop_get() to drop_download() and I have read posts on 409 error messages but I have not came up with a solution. Help on this is really appreciated. Thanks

> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=es_PR.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=es_PR.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=es_PR.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=es_PR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] httr_1.3.1        shiny_1.0.5       rdrop2_0.8.1.9999

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13    digest_0.6.12   mime_0.5        R6_2.2.2        xtable_1.8-2    jsonlite_1.5   
 [7] magrittr_1.5    curl_3.0        tools_3.4.2     httpuv_1.3.5    yaml_2.1.14     rsconnect_0.8.5
[13] compiler_3.4.2  htmltools_0.3.6 openssl_0.9.7 

JoseBartolomei avatar Oct 25 '17 19:10 JoseBartolomei

@JoseBartolomei, I see you've updated rdrop2; are you still using the same token from v0.7? You'll need to generate a new one with drop_auth, as the new Dropbox API v2 endpoints aren't backwards-compatible with v1 tokens.

ClaytonJY avatar Oct 25 '17 19:10 ClaytonJY

Thanks for your response.

Yes. I deleted the history, token and the .httr-oauth and then generated a new token but did not solve the warning issue.

JoseBartolomei avatar Oct 25 '17 19:10 JoseBartolomei

How are you loading the token in your shiny server?

We recommend saving the token to disk outside the app

token <- drop_auth()
saveRDS(token, "my-token.rds")

Then storing that with the app and passing it to drop_auth in global.R

drop_auth(rdstoken = "my-token.rds")`

If for some reason that still causes issues, you can also reload the token into the global state, and pass it to each rdrop2 function:

token <- readRDS("my-token.rds")
drop_download("my_file", dtoken = token)

ClaytonJY avatar Oct 25 '17 19:10 ClaytonJY

Hi,

I have being doing some testing to understand the problem.

In previous version of my app if a file within DropBox did not exist a "Do Not Found" message appears. Now, probably due to updates in rDrop2, instead of displaying the above message the app disconnect from server displaying the 409 error message.

Does this make sense?

At least is what it seems to be happening to me.

Below a simple example of a shiny app that can be use to illustrate the issue that render the following error message when I provide the files of the A and B input but not the files of the C input:

Downloading: 94 B     Warning: Error in drop_download: Conflict (HTTP 409).
Stack trace (innermost first):
    60: <Anonymous>
    59: stop
    58: httr::stop_for_status
    57: drop_download
    56: observerFunc [/media/veracrypt2/Shiny/rDrop_ShinyTest/app.R#53]
     1: shiny::runApp

###
library(shiny)
library(rdrop2)
library(httr)

ui <- # Define UI for dataset viewer application
  
  shinyUI(pageWithSidebar(
    
    headerPanel("Test DropBox html Docs to Shiny"),  
    
    sidebarPanel(
      
      selectInput("Cat", "Choose a Category:", 
                  
                  choices = c("A", "B", "C")),
      
      selectInput("Year", "Choose a Year:", 
                  
                  choices = c("2012", "2011")),	width = 2),
    
    
    mainPanel(
      
      tabsetPanel(type = "tabs", 
                  
                  tabPanel("Html Pages", htmlOutput("viewReport"))), width = 10)
    
  ))

# The two lines below needs to be run just one time unless the token is deleted

# Create Token

# token <- drop_auth()

# Save token

# saveRDS(token, "droptoken.rds")

token <- readRDS("droptoken.rds")

server <- shinyServer(function(input, output) {
  
  filePutReport <- reactive(
    
    paste(input$Cat, "_", input$Year,	"_Doc.html", sep = "")
    
  )

  observe({
    
    drop_download(path = paste("ShinyDbTest/", filePutReport(), sep = ""),
                  overwrite = TRUE, local_path = "./www",
             dtoken = token)
  })
  
  # Show Html Pages	
  
  output$viewReport <- renderUI({
    
    tags$iframe(seamless = "seamless", width = "1400", height = "1000",
                
                src = filePutReport())
    
  })
  
})

shinyApp(ui = ui, server = server)

JoseBartolomei avatar Oct 26 '17 17:10 JoseBartolomei

Hi, As another test I used again the deprecated drop_get() and it displayed the "Do not Found" message. drop_download disconnected displaying the 409 error message.

Would be nice to have a "Do not Found" message when using the new drop_download. It is possible? Thanks

JoseBartolomei avatar Oct 26 '17 17:10 JoseBartolomei

@JoseBartolomei sorry for the late reply. Yes, I agree we shouldn't just pass the error through. We're working on refactoring the "guts" of this package, so it might be a bit before we make an update, but in the meantime I'd recommend using purrr::safely or purrr::possibly to catch and handle this error.

ClaytonJY avatar Nov 13 '17 03:11 ClaytonJY

@ClaytonJY Thanks your for your response.

I trace(drop_download, edit = TRUE) and found that the line httr::stop_for_status(req) is the one that is stopping the app.

When I deleted httr::stop_for_status(req) the app continue as expected.

The downside of deleting httr:stop_for_status() is not having the messages of failure that is probably more useful in other cases than mine. Furthermore, I changed to httr::message_for_status(req) and found that it does not stop the app but displayed a not useful message for users.

To avoid the display of the aforementioned message and to not modify the function drop_download(), earlier today, I made a work around within the app that display a custom message and do not stop the app.

Below I included the server side of the app with the work around. The ui.R is in a previous message.

purrr::safely or purrr::possibly did not worked for me in this case.

Thanks for the development of this useful R package. I will look forward for the new rDrop2 version.

token <- readRDS("droptoken.rds")

server <- shinyServer(function(input, output) {
  
  filePutReport <- reactive(
    
    paste(input$Cat, "_", input$Year,	"_Doc.html", sep = "")
    
  )
  
  filePutReport2 <- reactive({
   
  if(drop_exists(paste("ShinyDbTest/", filePutReport(), sep = "")) == FALSE){
  
      "File_Not_Available.html"
      
     
    } else if(file.exists(file1 = paste("./www/", filePutReport(),
                                        sep = "")) == TRUE){
      
      paste(input$Cat, "_", input$Year,	"_Doc.html", sep = "")
      
    } else {
      
    drop_download(path = paste("ShinyDbTest/", filePutReport(), sep = ""),
                  overwrite = TRUE, local_path = "./www",
             dtoken = token)
    
      paste(input$Cat, "_", input$Year,	"_Doc.html", sep = "")
      
    } 
    
  })

  # Show Html Pages	
  
  output$viewReport <- renderUI({
    
    tags$iframe(seamless = "seamless", width = "1400", height = "1000",
                
                src = filePutReport2()
                )
  })
  
})

JoseBartolomei avatar Nov 13 '17 18:11 JoseBartolomei

@JoseBartolomei nice workaround; I think I like that better! Despite my last comment I'm back to thinking that drop_download throwing an error is the right behavior.

Something I didn't notice before: when the file doesn't exist, you still get a file on disk, but it's the error message as json. This makes me think drop_download should make a drop_exists check like what you did above, to avoid that.

ClaytonJY avatar Nov 14 '17 05:11 ClaytonJY

Hi @ClaytonJY @JoseBartolomei; I faced a similar problem seeing a HTTP 409 (conflict) message when I tried uploading/downloading a file to-from my Dropbox folder. I resolved it when I changed the format of the string to specify the relative path pointing to the source/destination of the file on my dropbox drive; NOTE, the relative path syntax differs to that used in 'drop_dir()' and 'drop_create()' image

SumanthLazarus avatar Nov 22 '19 11:11 SumanthLazarus