HTTP error 400 in R, error handling, How to retry instead of forcing to stop?

前端 未结 1 489
故里飘歌
故里飘歌 2020-12-22 00:23

I am calling API to download files using curl package in R. Due to unknown reason, sometimes the connection breaks with error code: Error in curl_download

相关标签:
1条回答
  • 2020-12-22 01:07

    There's a Hadley package designed exactly for this

    require(httr)
    maxTimes <- 10
    testFilename <- "testfile.txt"
    
    for (url in allUrl) {
      RETRY(verb = "GET", url = url, times = maxTimes,
        quiet = FALSE, terminate_on = NULL)
    }
    

    Specifially for file downloads with authentication, you can replace the RETRY command with:

    GET(url, write_disk(path=testFilename, overwrite=TRUE), authenticate("user", "passwd"))
    
    0 讨论(0)
提交回复
热议问题