Getting a Request Error 404 in Python while accessing an API

Question:

Previously, I used a Morningstar API to get stock data; however, now that I am away from USA for a week, I am not being able to access the data.

This is the code snippet:

import datetime as dt
from dateutil.relativedelta 
import relativedelta
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.data as web
import csv
from mpl_finance 
import candlestick_ohlc
import matplotlib.dates as mdates
from matplotlib.dates import DateFormatter, MonthLocator, YearLocator,    DayLocator, WeekdayLocator
style.use( 'ggplot' )


end = dt.date.today()

start_48 = end - relativedelta( years=4 )
start_120 = end - relativedelta( years=10 )

ticker = input( 'Ticker: ' ) #should be in Uppercase
ticker = ticker.upper()

df_w = web.DataReader( ticker, 'morningstar', start_48, end )
df_m = web.DataReader( ticker, 'morningstar', start_120, end )


print()

file_name_w = ticker + 'weekly.csv'
file_name_m = ticker + 'monthly.csv'
df_w.to_csv( file_name_w )
df_m.to_csv( file_name_m )

df_w = pd.read_csv( file_name_w, parse_dates=True, index_col=0 )
df_m = pd.read_csv( file_name_m, parse_dates=True, index_col=0 )

This is the error message:

Ticker: spy
Traceback (most recent call last):
File "/Users/zubairjohal/Documents/OHLC.py", line 24, in <module>
df_w = web.DataReader( ticker, 'morningstar', start_48, end )
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/data.py", line 391, in DataReader
session=session, interval="d").read()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/mstar/daily.py", line 219, in read
df = self._dl_mult_symbols(symbols=symbols)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/mstar/daily.py", line 130, in _dl_mult_symbols
resp.status_code, resp.reason))
Exception: Request Error!: 404 : Not Found

Is it an IP issue, and is there a way to fix this? I know that this code is fine because it worked perfectly well two days ago.

Asked By: zcdp

||

Answers:

404 means not found, assuming you didn’t make any change and suddenly doesn’t work I would say it is either that the API URL is not accessible in that country (or blocked in that specific network) or their API changed (or is under maintenance). If you know the API URL try it directly in a browser with different Internet connections.

Answered By: Andres

I had the same problem too, here in the USA. The datareader service (morningstar) worked 3 days ago and it stopped working a day before yesterday. I believe that morningstar changed here REST interface, so there is nothing much we can do except waiting on for the developers to fix it.

Answered By: Toan Pham