-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intermittent timeout issues with new getSymbols.yahoo as well as getSplits and getDividends #166
Comments
I also have this problem, i need to insert Sys.sleep(60) between each getXXXXX. |
I've noticed similar intermittent behavior at the beginning of a clean R session, but calling I've run @the-tourist-'s example a few times in a new R session, but it works for me... Can someone please provide a reproducible example that produces the behavior somewhat frequently? I know this is an intermittent issue, but I need code I can run to reliably reproduce the issue in order to investigate. Please provide as much detail as possible. Does it happen at the start of a new/clean R session? Or after the R session has been running for awhile? Does it stop working after prior calls to |
Hi Joshua, I run below script in command prompt, it will no problem for first few run, but after it, it will show ####test.r
.libPaths("C:/Users/goI/Documents/R/win-library/3.4")
library(quantmod)
library(TTR)
args <- commandArgs(TRUE)
stockNumber <- args[1]
fromDate <- args[2]
toDate <- args[3]
stock = getSymbols(stockNumber, auto.assign=FALSE ,from=fromDate , to=toDate,src="yahoo")
print(Cl(stock))
|
i run below code using rscript.exe in command prompt with 5 times, it will have "Could not establish session after 5 attempts." for 3 times. ####Scripts
test.r
h <- (curl::new_handle())
tmp <- tempfile()
for (i in 1:5) {
curl::curl_download("https://finance.yahoo.com", tmp, handle = h)
if (NROW(curl::handle_cookies(h)) > 0)
curl::handle_cookies(h)
break;
}
if (NROW(curl::handle_cookies(h)) == 0)
stop("Could not establish session after 5 attempts.")
####Scripts
|
@bennysiu Thanks for the examples! I see some failed attempts (i.e. the value of
Where #!/usr/bin/Rscript
.libPaths("~/R/library")
tmp <- tempfile()
on.exit(unlink(tmp))
h <- curl::new_handle()
for (i in 1:5) {
curl::curl_download("https://finance.yahoo.com", tmp, handle = h)
n <- NROW(curl::handle_cookies(h))
if (n > 0)
break
cat(i, "\n")
}
if (n == 0)
quit("no", status = 1) That said, I've let that command run for ~5 minutes and didn't encounter an instance where it failed 5 times and therefore exited with status = 1. Maybe it is related to your physical location? Also, what version of the curl package are you using? Here's a version that actually calls #!/usr/bin/Rscript
.libPaths("~/R/library")
suppressMessages(require(quantmod))
options("getSymbols.yahoo.warning"=FALSE)
options("getSymbols.warning4.0"=FALSE)
x <- try(getSymbols("SPY;EEM;AGG;IWM"))
if (inherits(x, "try-error")) {
quit("no", status = 1)
} else {
quit("no", status = 0)
} |
Joshua, The scripts I am using are running on a server in France with 10mbs up and down stream bandwidths. Doing a ping of finance.yahoo.com takes about 30ms when I tried it just now. I am working around the issue by using tryCatch and repeated calls with a small delay until it works, but maybe this could be moved into the quantmod code instead? |
Some users are still experiencing intermittent issues importing data from Yahoo Finance. Add 100ms between each connection attempt, and also use a new handle. See #166.
@the-tourist- |
Hi, I just retried the alternate version, but still received the same message. |
Thanks for the feedback! |
Trying to fetch the Yahoo Finance! homepage multiple times can result in getting a cached response from a proxy. The cached response does not have a "Set-cookie" header, so the curl handle will still not have a cookie and the connection will be retried. This StackOverflow Q/A has two approaches to avoid a cache hit: https://stackoverflow.com/q/31653271/271616 1) Add a "Cache-control: no-cache" header 2) Add a random query to the URL. The first approach didn't work because it appears the Yahoo proxies simply ignore the request. The second approach did work though. Fixes #166.
@the-tourist-, @bennysiu I just pushed a commit that seems to fix this issue. Please test and let me know if it works for you too. |
Is it committed to the master or to the 166_getSymbols_timeout branch? |
It's only on the 166_getSymbols_timeout branch right now. |
@joshuaulrich it would appear to be working. I tried calling a simple getSymbols script from the command line and after calling it 10 times I have not encountered the curl session error. Thanks. |
Awesome, thanks for the feedback! |
Some users are still experiencing intermittent issues importing data from Yahoo Finance. Add 100ms between each connection attempt, and also use a new handle. See #166.
it works great for me too. Thanks joshuaulrich. |
Hi! more related problems like this in the last 2 days:
Thanks for your help! |
Description
I am intermittently getting what appear to be timeout errors with getSymbols, getSplits and getDividends using yahoo as the source. Most of the time these work but moderately often I get
Error in new.session(curl::new_handle()) :
Could not establish session after 5 attempts.
Expected behavior
The results of the calls
Minimal, reproducible example
Session Info
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] quantmod_0.4-9 TTR_0.23-1 xts_0.9-7 zoo_1.8-0
loaded via a namespace (and not attached):
[1] compiler_3.4.0 tools_3.4.0 curl_2.6 grid_3.4.0 lattice_0.20-35
The text was updated successfully, but these errors were encountered: