【发布时间】:2021-11-25 08:29:06
【问题描述】:
我看到很多关于curl 的超时问题的问题。但是,我仍然对我的情况感到困惑。
我在使用quantmod::getSymbols 时出现问题。每次试验都以
Warning message:
x = 'AAPL', get = 'stock.prices': Error in curl::curl_fetch_memory(cu, handle = h): Timeout was reached: [finance.yahoo.com] Operation timed out after 10008 milliseconds with 0 out of 0 bytes received
注意我正在使用代理。我已尝试打开和关闭代理或运行
httr::set_config(httr::use_proxy(
"127.0.0.1:xxxxxx", port = 8080,
username = "xxxx", password = "****"
), override = TRUE)
但是,没有任何效果。
在对quantmod的内部细节感到困惑之后,我决定在纯curl_fetch_memory上进行实验。
-
curl_fetch_memory的文档中的示例在我的电脑上可以正常运行
curl::curl_fetch_memory("http://httpbin.org/cookies/set?foo=123&bar=ftw")
-
curl_fetch_memory不适用于"https://finance.yahoo.com/"(请注意,如果没有我的代理,我无法通过网络浏览器访问该网站) -
以下代码可以成功从https://finance.yahoo.com/获取结果:
curl_opts <- list(
ssl_verifypeer = 0L,
proxyuserpwd = "xxxx:****",
proxyauth = as.integer(15),
proxy = "127.0.0.1:xxxxxx",
proxyport = 8080
)
cookie_handler <- curl::new_handle()
curl::handle_setopt(handle=cookie_handler, .list=curl_opts)
curl::curl_fetch_memory("https://finance.yahoo.com/",
handle = cookie_handler)
quantmod 似乎无法正确使用代理设置。但是,没有选项可以在包中的函数内设置代理。我该如何解决我的问题?
系统:
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
# ...
【问题讨论】: