Fix: Error in new.session() : Could not establish session after 5 attempts

In R, When I was applying a function getSymbols() and I was running the code

getSymbols(tick, from = from_date, to = to_date, warnings = FALSE, auto.assign = TRUE, src="yahoo")

got error “Error in new.session() : Could not establish session after 5 attempts” and didn’t get a result.

As getSymbols() is the function of Quantmod package. Quantmod is an R package that provides a framework for quantitative financial modeling and trading. It provides a rapid prototyping environment that makes modeling easier by removing the repetitive workflow issues surrounding data management and visualization.

Why “Error in new.session() : Could not establish session after 5 attempts” Error Occurred?

When getSymbols() run, Inside getSymbols() , .getHandle will called ans our source is “yahoo” src=”yahoo”. When it goes to yahoo, All the 5 calls to the yahoo website return with no cookies, hence the function fails.

How to Fix “Why “Error in new.session() : Could not establish session after 5 attempts” Error Occurred?”

When this error comes, Joshua Ulrich quickly published the fix. That time you can install the patched version and that error will be gone

Quick Fix Patched Version:

remotes::install_github("joshuaulrich/quantmod@358-getsymbols-new.session")

But Now all the changes are pushed into CRAN. So

To Fix “Error in new.session() : Could not establish session after 5 attempts” error, just update the QuantMod package and your error will be gone.

install.packages('quantmod')

We hope by running the above code or updating the QuantMod package your error gone.