Skip to content

Yahoo source results in HTTP 429 error code #118

Description

@phantom-voltage

As a first time user of beanprice, I tested out the functionality, and could not get it to work.

bean-price --no-cache -e 'USD:yahoo/AAPL'

This results in the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/simplejson/__init__.py", line 533, in loads
    return cls(encoding=encoding, **kw).decode(s)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/usr/lib/python3.13/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ~~~~~~~~~~~~~~~^^^
  File "/usr/lib/python3.13/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/bean-price", line 33, in <module>
    sys.exit(load_entry_point('beanprice==2.0.0', 'console_scripts', 'bean-price')())
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/beanprice/price.py", line 967, in main
    price_entries = sorted(price_entries, key=lambda e: e.currency)
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.13/site-packages/beanprice/price.py", line 596, in fetch_price
    srcprice = fetch_cached_price(source, psource.symbol, dprice.date)
  File "/usr/lib/python3.13/site-packages/beanprice/price.py", line 497, in fetch_cached_price
    source.get_latest_price(symbol)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/usr/lib/python3.13/site-packages/beanprice/sources/yahoo.py", line 148, in get_latest_price
    result = parse_response(response)
  File "/usr/lib/python3.13/site-packages/beanprice/sources/yahoo.py", line 40, in parse_response
    json = response.json(parse_float=Decimal)
  File "/usr/lib/python3.13/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Through some print debugging, I noticed the response code received was 429 or Too many requests.

Response: <Response [429]>
Reason: Too Many Requests
URL: https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL&fields=symbol%2CregularMarketPrice%2CregularMarketTime&exchange=NYSE&crumb=Too+Many+Requests%0D%0A&lang=en-US&corsDomain=finance.yahoo.com&.tsrc=finance
Headers: {'Date': 'Sun, 08 Jun 2025 20:46:37 GMT', 'Strict-Transport-Security': 'max-age=31536000', 'Server': 'ATS', 'Cache-Control': 'no-store', 'Content-Type': 'text/html', 'Content-Language': 'en', 'Referrer-Policy': 'no-referrer-when-downgrade', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Length': '19', 'Age': '0', 'Connection': 'keep-alive'}

Note, that I did try the changes suggested in this pull-request: #86
It did not change the behavior displayed above.
Another note, in my testing, I likely sent many requests to yahoo trying to get this to work, however the python trace was the same.

First Edit: It looks like they may have identified many users were using an undocumented API or both fc.yahoo.com and the other proposed url guce.yahoo.com/consent are out of date for establishing a session. Testing the URL provided in the print debugging showed this response body:

{"finance":{"result":null,"error":{"code":"Unauthorized","description":"User is unable to access this feature - https://bit.ly/yahoo-finance-api-feedback"}}}

Second Edit:
yfinance, which uses the same API and session establishment, is also facing similar errors and likely due to a change in Yahoo APIs. See ranaroussi/yfinance#2520

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions