Last answered:

21 Nov 2023

Posted on:

17 Nov 2023

1

Error while running the code? How to handle the error!

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[11], line 1
----> 1 F = wb.DataReader('F', data_source='yahoo', start='2005-1-1')
      2 F

File ~\anaconda3\Lib\site-packages\pandas\util\_decorators.py:210, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
    208         raise TypeError(msg)
    209     kwargs[new_arg_name] = new_arg_value
--> 210 return func(*args, **kwargs)

File ~\anaconda3\Lib\site-packages\pandas_datareader\data.py:379, in DataReader(name, data_source, start, end, retry_count, pause, session, api_key)
    367     raise NotImplementedError(msg)
    369 if data_source == "yahoo":
    370     return YahooDailyReader(
    371         symbols=name,
    372         start=start,
    373         end=end,
    374         adjust_price=False,
    375         chunksize=25,
    376         retry_count=retry_count,
    377         pause=pause,
    378         session=session,
--> 379     ).read()
    381 elif data_source == "iex":
    382     return IEXDailyReader(
    383         symbols=name,
    384         start=start,
   (...)
    390         session=session,
    391     ).read()

File ~\anaconda3\Lib\site-packages\pandas_datareader\base.py:253, in _DailyBaseReader.read(self)
    251 # If a single symbol, (e.g., 'GOOG')
    252 if isinstance(self.symbols, (string_types, int)):
--> 253     df = self._read_one_data(self.url, params=self._get_params(self.symbols))
    254 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
    255 elif isinstance(self.symbols, DataFrame):

File ~\anaconda3\Lib\site-packages\pandas_datareader\yahoo\daily.py:153, in YahooDailyReader._read_one_data(self, url, params)
    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:
    155     msg = "No data fetched for symbol {} using {}"

TypeError: string indices must be integers, not 'str'

1 answers ( 0 marked as helpful)
Instructor
Posted on:

21 Nov 2023

0

Hi Himanshu!
Thanks for reaching out.


Yahoo have recently made changes to their API so currently the code provided is unable to provide the dataset as shown in the video lectures. Potentially, this will only be a temporary issue (as have happened in the past), meaning that once Yahoo fix the related issues themselves, the code will start working again.
Of course, this depends entirely on their data teams, so we cannot guarantee the future outcome of these changes with certainty. Therefore, to ensure your smooth continuation with taking this course, please consider applying one of the following options (suggestions provided in order of preference according to us):
- use the *.csv files we've provided to the lectures
- use yfinance instead of pandas-datareader
- use pycryptodome or pycryptodomex (risking to use data that is not as reliable as of now)


Hope this helps.
Kind regards,
The 365 Team

Submit an answer