ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

OperationalError('no such table: _kv') - unable to retrieve any sort of data at all #2045

Closed Sampie314 closed 2 months ago

Sampie314 commented 2 months ago

Describe bug

not able to download data or retrieve any data using finance. I am running the code within a jupyter notebook running from an ssh linux environment. it seems to be an issue with the caching and i have determined that the cache directory is being created by yfinance:

(base) [~/.cache/py-yfinance]$ ls
tkr-tz.db  tkr-tz.db-shm  tkr-tz.db-wal

have tried to manually clear the cache and have yfinance recreate it by re-running the code but issue still persits.

Simple code that reproduces your problem

import yfinance as yf

yf.download('AAPL', start='2013-01-01')

Debug log

DEBUG    Entering download()
DEBUG     Disabling multithreading because DEBUG logging enabled
DEBUG     Entering history()
ERROR     
          1 Failed download:
ERROR     ['AAPL']: OperationalError('no such table: _kv')
DEBUG     ['AAPL']: Traceback (most recent call last):
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 3322, in execute_sql
              cursor.execute(sql, params or ())
          sqlite3.OperationalError: no such table: _kv

          During handling of the above exception, another exception occurred:

          Traceback (most recent call last):
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/yfinance/multi.py", line 268, in _download_one
              data = Ticker(ticker).history(
                     ^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/yfinance/utils.py", line 104, in wrapper
              result = func(*args, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/yfinance/base.py", line 78, in history
              return self._lazy_load_price_history().history(*args, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/yfinance/base.py", line 84, in _lazy_load_price_history
              self._price_history = PriceHistory(self._data, self.ticker, self._get_ticker_tz(self.proxy, timeout=10))
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/yfinance/base.py", line 92, in _get_ticker_tz
              tz = c.lookup(self.ticker)
                   ^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/yfinance/cache.py", line 169, in lookup
              return _KV.get(_KV.key == key).value
                     ^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 6833, in get
              return sq.get()
                     ^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 7285, in get
              return clone.execute(database)[0]
                     ^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 2036, in inner
              return method(self, database, *args, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 2107, in execute
              return self._execute(database)
                     ^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 2280, in _execute
              cursor = database.execute(self)
                       ^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 3330, in execute
              return self.execute_sql(sql, params)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 3320, in execute_sql
              with __exception_wrapper__:
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 3088, in __exit__
              reraise(new_type, new_type(exc_value, *exc_args), traceback)
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 196, in reraise
              raise value.with_traceback(tb)
            File "/{hidden_dir}/.conda/envs/fypmain/lib/python3.12/site-packages/peewee.py", line 3322, in execute_sql
              cursor.execute(sql, params or ())
          peewee.OperationalError: no such table: _kv

DEBUG    Exiting download()

Bad data proof

No response

yfinance version

0.2.43

Python version

python 3.12.3

Operating system

NAME="Rocky Linux" VERSION="9.4 (Blue Onyx)"

ValueRaider commented 2 months ago

This should be impossible but clearly it happened. What version of peewee package?

And try branch fix/cache-exceptions #1080

Sampie314 commented 2 months ago
$ conda list | grep yfinance
yfinance                  0.2.18             pyhd8ed1ab_0    conda-forge
$ conda list | grep peewee
peewee                    3.17.6           py39h94e0435_0    conda-forge

will look into the branch

ValueRaider commented 2 months ago

0.2.18

This is not 0.2.43