Skip to content

Unable to fetch stock data from yahoo! #995

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

Open
vikassnwl opened this issue Aug 25, 2024 · 4 comments
Open

Unable to fetch stock data from yahoo! #995

vikassnwl opened this issue Aug 25, 2024 · 4 comments

Comments

@vikassnwl
Copy link

Run the following code to reproduce the issue:

import pandas_datareader as web
web.DataReader("AAPL", "yahoo", "1/1/2018", "1/1/2019")

You will get the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/vikas/.local/lib/python3.8/site-packages/pandas/util/_decorators.py", line 210, in wrapper
    return func(*args, **kwargs)
  File "/home/vikas/.local/lib/python3.8/site-packages/pandas_datareader/data.py", line 370, in DataReader
    return YahooDailyReader(
  File "/home/vikas/.local/lib/python3.8/site-packages/pandas_datareader/base.py", line 253, in read
    df = self._read_one_data(self.url, params=self._get_params(self.symbols))
  File "/home/vikas/.local/lib/python3.8/site-packages/pandas_datareader/yahoo/daily.py", line 152, in _read_one_data
    j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
AttributeError: 'NoneType' object has no attribute 'group'
@r-vvch
Copy link

r-vvch commented Sep 16, 2024

Same issue

@Quelconque
Copy link

Problem seem to be caused by this code snippet (at line 149 in yahoo/daily.py):
try:
j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
except KeyError as exc:
msg = "No data fetched for symbol {} using {}"
raise RemoteDataError(msg.format(symbol, self.class.name)) from exc

if pattern is not found, re.search() returns None while the programmer was expecting a KeyError exception.

Nobody fixed the problem in the last 8 months.
Is there still a pilot on this plane?

@sugizo
Copy link

sugizo commented May 20, 2025

code

import pandas_datareader.data as web
st = dt.datetime(2024, 1, 11)
en = dt.datetime(2024, 1, 19)
data = web.get_data_yahoo('AAPL', start = st, end = en)
print(data)

result

AttributeError                            Traceback (most recent call last)
[<ipython-input-4-983731377189>](https://localhost:8080/#) in <cell line: 0>()
----> 1 data = web.get_data_yahoo('AAPL', start = st, end = en)
      2 print(data)

2 frames
[/usr/local/lib/python3.11/dist-packages/pandas_datareader/yahoo/daily.py](https://localhost:8080/#) in _read_one_data(self, url, params)
    150         ptrn = r"root\.App\.main = (.*?);\n}\(this\)\);"
    151         try:
--> 152             j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))
    153             data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
    154         except KeyError:

AttributeError: 'NoneType' object has no attribute 'group'

best regards

@parinayrana
Copy link

It seems the data pattern on the Yahoo Finance site has changed, and the code in the pandas_datareader library is still based on the older pattern.

So I tried using the yfinance library instead, and it worked:

import yfinance as yf
import datetime as dt

start = dt.datetime(2000, 1, 1)
end = dt.datetime(2024, 12, 31)

# Download historical data
df = yf.download("TSLA", start, end)

print(df.head())

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.

5 participants