joshuabach / gnucash-web

A simple, mobile-friendly webinterface for GnuCash
GNU General Public License v3.0
119 stars 18 forks source link

Yahoo finance requires authorization #60

Open joshuabach opened 10 months ago

joshuabach commented 10 months ago

Yahoo finance seems to have discontinued their public API (worked last in Mai 2023).

Running gnucash-web commodities update_prices for my stocks results in

Traceback (most recent call last):
  File "/home/joshua/gnucash_web/ENV/bin/gnucash-web", line 8, in <module>
    sys.exit(cli())
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/flask/cli.py", line 600, in main
    return super().main(*args, **kwargs)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/flask/cli.py", line 444, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/gnucash_web/commodities.py", line 98, in update_prices
    commodity.update_prices()
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/piecash/core/commodity.py", line 319, in update_prices
    share = get_latest_quote(symbol)
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/piecash/yahoo_client.py", line 31, in get_latest_quote
    resp.raise_for_status()
  File "/home/joshua/gnucash_web/ENV/lib64/python3.9/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://query1.finance.yahoo.com/v7/finance/quote?symbols=SYMBOL

Yahoo Finance is hardcoded in Piecash. We need to find a different solution. There probably is no service left that doesn't require an API key, so we might have to resort to that. Alphavantage seems promising.