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

SQLite driver not installed! #2124

Open dsoeiro opened 1 week ago

dsoeiro commented 1 week ago

Describe bug

When running the Google Cloud Function with the latest version of Python and yfinance, the error SQLite driver not installed! occurred. This issue arose because the yfinance library attempts to use SQLite for caching, but the required SQLite driver is not available in the Cloud Function environment. As a result, the function failed to retrieve data properly (response: 'SQLite driver not installed!'). However, when using an older version like yfinance==0.1.63, it works, but returns zero results. If you run the same code locally with the latest version of both Python and yfinance, it works normally without any issues.

Simple code that reproduces your problem

from flask import jsonify, abort, request import yfinance as yf

def main(request):

request_json = request.get_json(silent=True)
symbol = request_json.get("symbol") if request_json else None

if not symbol:
    abort(400, "Symbol is required")

try:

    company = yf.Ticker(symbol)
    stock_info = {
        'market_cap': company.info.get('marketCap', None),
        'avg_volume': company.info.get('averageVolume', None),
        'dividend_yield': company.info.get('dividendYield', None),
        'forward_pe': company.info.get('forwardPE', None),
        'beta': company.info.get('beta', None),
        'profit_margins': company.info.get('profitMargins', None),
        'return_on_assets': company.info.get('returnOnAssets', None),
        'return_on_equity': company.info.get('returnOnEquity', None),
    }
    return jsonify(stock_info)
except Exception as e:
    return jsonify({"error": str(e)}), 500

request

response


requirements.txt

flask yfinance

Debug log

https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL textPayload: "DEBUG params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'AAPL'}"

textPayload: "DEBUG cookie_mode = 'basic'"

textPayload: "DEBUG Entering _get_cookie_and_crumb()"

Bad data proof

No response

yfinance version

last

Python version

Python 3.12

Operating system

No response

ValueRaider commented 1 week ago

yfinance/cache.py already has logic for coping with a read-only cache folder, so probably it can be extended to also handle sqlite missing: https://github.com/ranaroussi/yfinance/blob/dfe3ec8df7be8da5e6addc629ed8dfa95e2f896d/yfinance/cache.py#L133

dsoeiro commented 1 week ago

thanks @ValueRaider . Understood, thank you for the explanation. Is there anything I can contribute to help address this point? For example, would additional testing in environments where SQLite is unavailable be useful, or is there another way I could support this implementation?

ValueRaider commented 1 week ago

You could develop and test a fix for missing sqlite? #1084