Black Lives Matter. Please consider donating to Black Girls Code today.
https://www.blackgirlscode.com

Sudden urllib.error.HTTPError: HTTP Error 404: Not Found after many successful executions

Hi!

I had my Dash application working smoothly, when all of the sudden (without making any changes in code), The following error occurs and the app crashes:

 File "index.py", line 7, in <module>
    from layouts import lecture_43, noPage
  File "C:\Users\PC04\Documents\gdp-quant-academy\layouts.py", line 9, in <module>
    from lecture43 import lecture_43
  File "C:\Users\PC04\Documents\gdp-quant-academy\lecture43.py", line 77, in <module>
    datetime(t_end.year, t_end.month, t_end.day, 21, 0).timestamp())},
  File "C:\Users\PC04\Documents\gdp-quant-academy\lecture43.py", line 53, in real_data_from_ticker
    real_data = pd.read_csv(query)
  File "C:\Users\PC04\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 702, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\PC04\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 413, in _read
    filepath_or_buffer, encoding, compression)
  File "C:\Users\PC04\Anaconda3\lib\site-packages\pandas\io\common.py", line 202, in get_filepath_or_buffer
    req = _urlopen(filepath_or_buffer)
  File "C:\Users\PC04\Anaconda3\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\PC04\Anaconda3\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Users\PC04\Anaconda3\lib\urllib\request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\PC04\Anaconda3\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Users\PC04\Anaconda3\lib\urllib\request.py", line 503, in _call_chain
    result = func(*args)
  File "C:\Users\PC04\Anaconda3\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 even tried restoring the repository to the latest working instance, and again it crashes with that excat same error.

I really don’t know what to do about it.

Thanks in advance!

it looks like your app is downloading some data from the internet (a csv file) and that file is no longer available. when resources are no longer available, requests will usually fail with a β€œ404” error

Thank you for your answer.
I came to the same conclusion but what I find wired is that the exact same code worked just seconds before that error, and I tried to download that resource in a separate script and also worked. It is a CSV document from Yahoo finance.

I will keep no working with it and update you if I find anything useful. Thank you very much! @chriddyp

Yahoo finance might be rate-limiting your app - many API services will prohibit too many requests from happening within a certain amount of time. Good luck!

Yeah that sound probable.
I think it would be better to just save information locally and updating daily, while I work on a solution with a different API to get financial data.

Thank you! @chriddyp

You could also consider using a CachedSession. If you want to get a new file once a day, you can just set the timeout to 60 * 60 * 24 (one day in seconds), and keep your code otherwise as-is.

1 Like

Never heard of Cached Session. Thank you very much for the insight @Emil