我看到了很多关于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
# ...
发布于 2021-10-05 02:02:29
我想我已经找到解决办法了。您只需要打开代理并运行
Sys.setenv(ALL_PROXY = "YOUR_PROXY_HOST")
在请求之前。
但是,目前我仍然不知道curl
如何使用设置ALL_PROXY
。如果有人能给我一个解释,我会很感激的。
https://stackoverflow.com/questions/69444027
复制相似问题