1

I'm using the Yahoo Financials package on python to retrieve stock data. I have a list of about 30 stocks that I'm interested in and I wrote a script to loop through this list, extract the closing price and use that data to build a dataframe.

However, I encounter the following TimeoutError:

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

It also states that another error occurred while handling the above:

OSError: [Errno socket error] [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

My code is as follows:

stistocks = ["U96.SI", "D01.SI", "J36.SI", "O39.SI", "BN4.SI", "N2IU.SI", "BS6.SI", "G13.SI", "V03.SI", "S63.SI", "F34.SI", "S68.SI", "C52.SI", "Z74.SI",
"A17U.SI", "U11.SI", "H78.SI", "M44U.SI", "C31.SI", "U14.SI", "J37.SI", "T39.SI", "C6L.SI", "S58.SI", "D05.SI", "C38U.SI", "C09.SI", "C61U.SI", "C07.SI", "Y92.SI", "A35.SI"]

factor = 0

for ticker in stistocks:
    yahoo_financials = YahooFinancials(ticker)
    historical_data = yahoo_financials.get_historical_price_data('2000-01-01', '2020-07-17', 'daily')
    historical_stock_prices = historical_data[ticker]["prices"]
    date_list = [each_day["formatted_date"] for each_day in historical_stock_prices]
    price_list = [each_day["adjclose"] for each_day in historical_stock_prices]
    if factor == 0:
        data = {"Date": date_list, ticker:price_list}
        df_first = pd.DataFrame.from_dict(data)
        df_first["Date"] = pd.to_datetime(df_first["Date"], format="%Y-%m-%d")
        factor = factor + 1
    else:
        data = {"Date": date_list, ticker:price_list}
        df = pd.DataFrame.from_dict(data)
        df["Date"] = pd.to_datetime(df["Date"], format="%Y-%m-%d")
        df_first = df_first.merge(df, on="Date", how='outer')

1 Answers1

0

I've been having the same problem. It worked for maybe a year for me and now its randomly giving me this error. I've read many places that yfinance is buggy and maybe that's why, but even then are you using a different package? I've noticed if I decrease the amount of stocks it works and if it doesn't I've been just running it again.

It's possible that its an error somewhat like: Python: URLError: <urlopen error [Errno 10060]

which also links to: Why can't I get Python's urlopen() method to work on Windows? Using an HTTP PROXY - Python

I have no idea what a http proxy is but maybe there's some way to get around it like this? Not sure if the package directly finds the url and scrapes from there or something. Have you solved the problem already?

Ashley Adams
  • 95
  • 1
  • 12