Search code examples
pythonherokuyfinance

Heroku / Python - script stops with error


i have a python script which i want to run on the heroku plattform - everything seems fine and scheduled - but at the end i allways get an error when running on heroku (i see this in the papertrail logs)

When i run the script locally on my machine it works fine.

The error occurs when i want to read data using the yfinance module: (obviously in the last line)

tday = datetime.today()
startDay = tday - timedelta(days=2200)            
print(f"Read stock price data for {stock}...")
hist_price_stock = yf.download(stock,start=startDay,end=tday)

This is the error message which i get from heroku / papertrail: (on the first look it didn´t help me much)

Sep 04 03:13:12 scoresupdatetickers app/worker.1 Read stock price data for AAPL...
Sep 04 03:13:12 scoresupdatetickers app/worker.1 Exception in thread Thread-1:
Sep 04 03:13:12 scoresupdatetickers app/worker.1 Traceback (most recent call last):
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Sep 04 03:13:12 scoresupdatetickers app/worker.1     self.run()
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/threading.py", line 892, in run
Sep 04 03:13:12 scoresupdatetickers app/worker.1     self._target(*self._args, **self._kwargs)
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/site-packages/multitasking/__init__.py", line 102, in _run_via_pool
Sep 04 03:13:12 scoresupdatetickers app/worker.1     return callee(*args, **kwargs)
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/site-packages/yfinance/multi.py", line 167, in _download_one_threaded
Sep 04 03:13:12 scoresupdatetickers app/worker.1     data = _download_one(ticker, start, end, auto_adjust, back_adjust,
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/site-packages/yfinance/multi.py", line 179, in _download_one
Sep 04 03:13:12 scoresupdatetickers app/worker.1     return Ticker(ticker).history(period=period, interval=interval,
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/site-packages/yfinance/base.py", line 157, in history
Sep 04 03:13:12 scoresupdatetickers app/worker.1     data = data.json()
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/site-packages/requests/models.py", line 900, in json
Sep 04 03:13:12 scoresupdatetickers app/worker.1     return complexjson.loads(self.text, **kwargs)
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/json/__init__.py", line 346, in loads
Sep 04 03:13:12 scoresupdatetickers app/worker.1     return _default_decoder.decode(s)
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/json/decoder.py", line 337, in decode
Sep 04 03:13:12 scoresupdatetickers app/worker.1     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
Sep 04 03:13:12 scoresupdatetickers app/worker.1   File "/app/.heroku/python/lib/python3.9/json/decoder.py", line 355, in raw_decode
Sep 04 03:13:12 scoresupdatetickers app/worker.1     raise JSONDecodeError("Expecting value", s, err.value) from None
Sep 04 03:13:12 scoresupdatetickers app/worker.1 json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Sep 04 07:09:47 scoresupdatetickers heroku/scheduler.7291 Cycling
Sep 04 07:09:47 scoresupdatetickers heroku/scheduler.7291 State changed from up to complete
Sep 04 07:09:48 scoresupdatetickers heroku/scheduler.7291 Stopping all processes with SIGTERM
Sep 04 07:09:48 scoresupdatetickers heroku/scheduler.7291 Process exited with status 143

Any idea why this is only running locally and not when hosted on heroku?


Solution

  • yfinance is a python package.

    You have to update it's version to the latest one in your requirements.txt file and then push those changes to Heroku.

    Heroku will then install the updated version and then your app will be using the latest version of yfinance.