【问题标题】:Request URL failed/timeout in RR中的请求URL失败/超时
【发布时间】:2014-12-30 02:10:56
【问题描述】:

我正在尝试从 url 获取 csv 文件,但它似乎在一分钟后超时。 csv 文件是在请求时创建的,因此需要一分钟多一点。我尝试增加超时,但没有奏效,一分钟后仍然失败。

我使用urlread.csv如下:

# Start the timer
ptm <- proc.time()
urlCSV <- getURL("http://someurl.com/getcsv", timeout = 200)
txtCSV <- textConnection(urlCSV)
csvFile <- read.csv(txtCSV)
close(txtCSV)
# Stop the timer
proc.time() - ptm

结果日志:

Error in open.connection(file, "rt") : cannot open the connection
In addition: Warning message:
In open.connection(file, "rt") :
cannot open: HTTP status was '500 Internal Server Error'

user  system elapsed 
0.225   0.353  60.445

达到一分钟后一直失败,可能是什么问题?或者如何增加超时时间?

我在浏览器中尝试了 url,它工作正常,但加载 csv 需要一分钟以上

【问题讨论】:

    标签: r rest url csv rcurl


    【解决方案1】:

    libcurl 有一个 CONNECTTIMEOUT 设置 http://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html。 你可以在RCurl中设置这个:

    library(RCurl)
    > getCurlOptionsConstants()[["connecttimeout"]]
    [1] 78
    myOpts <- curlOptions(connecttimeout = 200)
    urlCSV <- getURL("http://someurl.com/getcsv", .opts = myOpts)
    

    【讨论】:

      【解决方案2】:

      您从 服务器 收到 500 错误,这表明那里正在发生超时,因此不在您的控制范围内(除非您可以要求更少的数据)

      【讨论】:

        猜你喜欢
        • 2019-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-14
        • 1970-01-01
        • 2019-10-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多