Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
harryho71 opened this issue Jun 24, 2023 · 6 comments · Fixed by #1574
Open

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

harryho71 opened this issue Jun 24, 2023 · 6 comments · Fixed by #1574
Assignees

Comments

@harryho71
Copy link

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

  • yfinance version: 0.2.21
  • Python version: 3.9.13
  • Operating system type: Window 11
@ValueRaider
Copy link
Collaborator

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

@harryho71
Copy link
Author

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

It works. Thanks a lot!

@oliverengel
Copy link

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

  • yfinance version: 0.2.43
  • Python version: 3.12.5
  • Operating system type: Window 11

Error message in file.
error message.txt

@ValueRaider
Copy link
Collaborator

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

@ValueRaider ValueRaider reopened this Aug 28, 2024
@ValueRaider ValueRaider self-assigned this Aug 28, 2024
@oliverengel
Copy link

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<USER>\AppData\Local\py-yfinance as suggested. But it didn't help.

After searching for other locations, I found C:\Users<USER>\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.

@ValueRaider
Copy link
Collaborator

Patch in branch fix/peewee-db-malformed, can you try? #1080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants