Forums

Internal server error.

I have made a flask app in python, that takes a StoreId and a Date and predicts Visitors based on date. Then predicts Sales with predicted visitors + date and lastly predicts employees with date + sales + visitors.

Everything works in postman, and all models are in their correct directorys on this site. A venv is pressent with all the packages needed.

The program catches a few errors. For example, there are 128 unique store ids and there is 128 unique models in each of the three folders "Employees Models, Visitors Models, and Sales Models". If the user gives a store id which does not have a model i get the correct error message printed to the webpage. So that works, it goes into the folders and dosent find the corresponding storeID and raises a error.

The problem is that when i enter a storeId that i know is valid, I get the Internal server error, so something must be wrong with the model loading as its complaining on NoneType is not callable?

This is the error log:

2023-11-30 07:50:46,409: Exception on /predict [GET]
Traceback (most recent call last):
  File "/home/Dencut98/.virtualenvs/flaskk/lib/python3.10/site-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/Dencut98/.virtualenvs/flaskk/lib/python3.10/site-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/Dencut98/.virtualenvs/flaskk/lib/python3.10/site-packages/flask/app.py", line 867, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/Dencut98/.virtualenvs/flaskk/lib/python3.10/site-packages/flask/app.py", line 852, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/home/Dencut98/TooEasy/main.py", line 86, in main
    employees_pred, sales_pred, visitor_pred = self.load_predictions(
  File "/home/Dencut98/TooEasy/main.py", line 204, in load_predictions
    predictions = self.make_prediction(features)
  File "/home/Dencut98/TooEasy/main.py", line 227, in make_prediction
    visitors_pred = self._visitors_model.predict(features)
  File "/home/Dencut98/.virtualenvs/flaskk/lib/python3.10/site-packages/lightgbm/sklearn.py", line 891, in predict
    X = _LGBMCheckArray(X, accept_sparse=True, force_all_finite=False)
TypeError: 'NoneType' object is not callable

You need to add some logging to your code to see what is the state of the variables and how it is different from expected state.