在python上使用Yahoo Financials时出现WinError 10060



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

然而,我遇到以下超时错误:

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

它还指出,在处理上述问题时发生了另一个错误:

OSError:[Erno套接字错误][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')

我也遇到了同样的问题。它对我来说可能工作了一年,现在它随机地给了我这个错误。我读过很多地方说yfnance有缺陷,也许这就是为什么,但即便如此,你还是在使用不同的软件包吗?我注意到,如果我减少库存量,它会起作用,如果不起作用,我就会再次运行它。

这可能是一个错误,有点像:Python:URLError:<urlopen错误[Erno 10060]

它还链接到:为什么可以';t我得到Python';s的urlopen((方法在Windows上工作?使用HTTP代理-Python

我不知道http代理是什么,但也许有办法像这样绕过它?不确定软件包是否直接找到url并从中抓取或其他什么。你已经解决问题了吗?

最新更新