YahooFinance的价格数据错误:TypeError:timedelta seconds组件的类型不受支持:NoneTyp

2024-04-19 07:30:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个大约250个股票符号的列表(例如“AAPL”、“IBM”、“QQQ”…),并尝试使用YahooFinancials从Yahoo Finance获取价格数据。你知道吗

nr_periods = 333

date_N_days_ago = (datetime.now() - timedelta(days = nr_periods)).strftime('%Y-%m-%d')
date_today = datetime.now().strftime('%Y-%m-%d')

yahoo_financials = YahooFinancials(symbols_list)
hist_prices = yahoo_financials.get_historical_price_data(date_N_days_ago, date_today, 'daily')

此代码导致错误消息:

TypeError: unsupported type for timedelta seconds component: NoneType

问题是这个错误消息不是每次我执行代码时都出现,而是随机出现的。我不明白为什么。这是完整的堆栈跟踪

Traceback (most recent call last):
  File "testfile.py", line 273, in <module>
    updatePrices(logger)
  File "testfile.py", line 185, in updatePrices
    hist_prices = yahoo_financials.get_historical_price_data(date_N_days_ago, date_today, 'daily')
  File "/usr/local/lib/python3.5/dist-packages/yahoofinancials/__init__.py", line 547, in get_historical_price_data
    return self.get_stock_data('history', hist_obj=hist_obj)
  File "/usr/local/lib/python3.5/dist-packages/yahoofinancials/__init__.py", line 428, in get_stock_data
    dict_ent = self._create_dict_ent(tick, statement_type, tech_type, report_name, hist_obj)
  File "/usr/local/lib/python3.5/dist-packages/yahoofinancials/__init__.py", line 364, in _create_dict_ent
    cleaned_re_data = self._clean_historical_data(re_data)
  File "/usr/local/lib/python3.5/dist-packages/yahoofinancials/__init__.py", line 270, in _clean_historical_data
    cleaned_date = self.format_date(v)
  File "/usr/local/lib/python3.5/dist-packages/yahoofinancials/__init__.py", line 111, in format_date
    form_date = str((datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=in_date)).date())
TypeError: unsupported type for timedelta seconds component: NoneType

Tags: inpydatagetdatetimedatelibpackages