pythonfinanceyahoo-financeyahooyahoo-api

urllib.error.HTTPError: HTTP Error 404: Not Found yfinance library


I keep getting this error while using:

import yfinance as yf

msft = yf.Ticker("MSFT")

msft.info

Traceback (most recent call last):
  Python Shell, prompt 15, line 6
  File "C:\Users\i\miniconda3\Lib\site-packages\yfinance\ticker.py", line 138, in info
    return self.get_info()
  File "C:\Users\i\miniconda3\Lib\site-packages\yfinance\base.py", line 415, in get_info
    self._get_fundamentals(proxy)
  File "C:\Users\i\miniconda3\Lib\site-packages\yfinance\base.py", line 284, in _get_fundamentals
    holders = _pd.read_html(url)
  File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 1100, in read_html
    displayed_only=displayed_only,
  File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 895, in _parse
    tables = p.parse_tables()
  File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 213, in parse_tables
    tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
  File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 733, in _build_doc
    raise e
  File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\html.py", line 714, in _build_doc
    with urlopen(self.io) as f:
  File "C:\Users\i\miniconda3\Lib\site-packages\pandas\io\common.py", line 141, in urlopen
    return urllib.request.urlopen(*args, **kwargs)
  File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "C:\Users\i\miniconda3\Lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

I have tried updating packages and uninstalling and reinstalling the library but nothing is seems to work.


Solution

  • According to this ticker, it's a bug in yfinance library.

    So let me read the comments:

    holders = _pd.read_html(url)
    

    with:

    r = _requests.get(url,headers={'User-Agent': 'Mozilla/5.0'})
    holders = _pd.read_html(r.content)
    
    pip install -i https://pypi.anaconda.org/ranaroussi/simple yfinance
    

    Tested last one, it works. Good luck.