'Error when downloading market data from yahoo finance
I have tried downloading market data from yahoo finance, but I kept on running into error. Here is my code:
import yfinance as yf
#import data of different asset classes
VT = yf.download("VT",interval="1d", start="2017-01-01", end="2021-01-01") #stocks
BND = yf.download("BND",interval="1d", start="2017-01-01", end="2021-01-01") #bonds
VNQ = yf.download("VNG",interval="1d", start="2017-01-01", end="2021-01-01") #real estate
DBC = yf.download("DBC",interval="1d", start="2017-01-01", end="2021-01-01") #commodities
This Error shows up:
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-2a474e2089b7> in <module>
1 #import data of different asset classes
----> 2 VT = yf.download("VT",interval="1d", start="2017-01-01", end="2021-01-01") #stocks
3 BND = yf.download("BND",interval="1d", start="2017-01-01", end="2021-01-01") #bonds
4 VNQ = yf.download("VNG",interval="1d", start="2017-01-01", end="2021-01-01") #real estate
5 DBC = yf.download("DBC",interval="1d", start="2017-01-01", end="2021-01-01") #commodities
~/anaconda3/lib/python3.7/site-packages/yfinance/multi.py in download(tickers, start, end, actions, threads, group_by, auto_adjust, back_adjust, progress, period, interval, prepost, proxy, rounding, **kwargs)
93 rounding=rounding)
94 while len(shared._DFS) < len(tickers):
---> 95 _time.sleep(0.01)
96
97 # download synchronously
KeyboardInterrupt:
Solution 1:[1]
Try This:
import datetime as dt
import pandas as pd
import yfinance as yf
from pandas_datareader import data as pdr
tickers = ["AAPL","GOOG","AMZN"]
yf.download(tickers, start = "2021-02-01" , end = "2021-02-04")
Solution 2:[2]
your queries are fine, it looks like a timing issue between your network and Yahoo finance, you might want to add a delay between requests or retry look up retry
Vanguard is great according to Warren Buffet... (VT)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Portfedh |
| Solution 2 | Zen4ttitude |
