【问题标题】:WinError 10060 when using Yahoo Financials on python在 python 上使用 Yahoo Financials 时出现 WinError 10060
【发布时间】:2020-07-20 12:39:17
【问题描述】:

我在 python 上使用 Yahoo Financials 包来检索股票数据。我有一个大约 30 只我感兴趣的股票的列表,我编写了一个脚本来循环遍历该列表,提取收盘价并使用该数据构建一个数据框。

但是,我遇到以下 TimeoutError:

[WinError 10060] 连接尝试失败,因为连接的一方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。

它还指出在处理上述情况时发生了另一个错误:

OSError: [Errno socket error] [WinError 10060] 连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应。

我的代码如下:

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')

【问题讨论】:

    标签: python-3.x yahoo-finance


    【解决方案1】:

    我也遇到了同样的问题。它对我来说可能工作了一年,现在它随机给了我这个错误。我读过很多地方说 yfinance 有问题,也许这就是原因,但即便如此,您是否使用不同的包? 我注意到如果我减少它有效的股票数量,如果没有,我就重新运行它。

    它的错误可能有点像: Python: URLError: <urlopen error [Errno 10060]

    它还链接到: Why can't I get Python's urlopen() method to work on Windows? Using an HTTP PROXY - Python

    我不知道什么是 http 代理,但也许有一些方法可以像这样绕过它?不确定包是否直接找到了 url 并从那里抓取或其他东西。 你已经解决问题了吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-14
      • 2020-09-01
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多