ranaroussi / yfinance

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

DatabaseError('database disk image is malformed') #1573

Open harryho71 opened 1 year ago

harryho71 commented 1 year ago

Problem

I cannot download historical stock data with yfinance

Simple code that reproduces your problem

data = yf.download("SPY", start="2017-01-01", end="2017-04-30")

Full debug logging enabled output

DEBUG Entering download() DEBUG Disabling multithreading because DEBUG logging enabled DEBUG Entering history() ERROR
1 Failed download: ERROR ['SPY']: DatabaseError('database disk image is malformed') DEBUG ['SPY']: Traceback (most recent call last): File "C:\Users\harry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\yfinance\multi.py", line 273, in _download_one data = Ticker(ticker, session=session).history( File "C:\Users\harry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\yfinance\utils.py", line 105, in wrapper result = func(*args, **kwargs) File "C:\Users\harry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\yfinance\base.py", line 153, in history tz = self._get_ticker_tz(proxy, timeout) File "C:\Users\harry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\yfinance\base.py", line 1409, in _get_ticker_tz cache = utils.get_tz_cache() File "C:\Users\harry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\yfinance\utils.py", line 1045, in get_tz_cache _tz_cache = _TzCache() File "C:\Users\harry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\yfinance\utils.py", line 958, in init self._tz_db = _KVStore(_os.path.join(self._db_dir, "tkr-tz.db")) File "C:\Users\harry\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\yfinance\utils.py", line 900, in init self.conn.execute('pragma journal_mode=wal') sqlite3.DatabaseError: database disk image is malformed

DEBUG Exiting download()

Version

ValueRaider commented 1 year ago

Try GitHub branch hotfix/sql-db-error - instructions #1080.

harryho71 commented 1 year ago

Try GitHub branch hotfix/sql-db-error - instructions #1080.

It works. Thanks a lot!

oliverengel commented 2 weeks ago

Since today, the DatabaseError comes up again, but with peewee.

Error message in file. error message.txt

ValueRaider commented 2 weeks ago

Re-patching will take time as the caching has completely changed since the previous patch. Quickest fix should be deleting the database: https://github.com/ranaroussi/yfinance#persistent-cache-store

oliverengel commented 2 weeks ago

Re-patching will take time as the caching has completely changed since the previous patch. Quickest fix should be deleting the database: https://github.com/ranaroussi/yfinance#persistent-cache-store

First, I deleted the database in C:\Users\\AppData\Local\py-yfinance as suggested. But it didn't help.

After searching for other locations, I found __C:\Users\\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\Local\py-finance__. This one did the fix. Not sure, if it has something to do that I worked in a virtual environment.