KeyError: 159

Hello all,

I am quite confused.

I added a .streamlit/config.toml today and got the following error. This error also occurs when I add e.g. empty line in the .py. So it can’t be the code, it was working exactly as it is before.

KeyError: 159

File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/”, line 552, in _run_script
exec(code, module.dict)
File “/mount/src/stroke_probability/”, line 66, in
svm1, svm2, logit1, logit2, nbc1, nbc2, rf1, rf2, errGBR = loadAllModels(URL)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/”, line 211, in wrapper
return cached_func(*args, **kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/”, line 240, in call
return self._get_or_create_cached_value(args, kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/”, line 266, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/caching/”, line 320, in _handle_cache_miss
computed_value = self._info.func(*func_args, **func_kwargs)
File “/mount/src/stroke_probability/”, line 58, in loadAllModels
File “/home/adminuser/venv/lib/python3.9/site-packages/joblib/”, line 577, in load
obj = _unpickle(fobj)
File “/home/adminuser/venv/lib/python3.9/site-packages/joblib/”, line 506, in _unpickle
obj = unpickler.load()
File “/usr/local/lib/python3.9/”, line 1212, in load

Hi @frankmollard,

Thank you for your question!

The error traceback suggests a KeyError arising when trying to load a model using joblib. Is the path to the model file (URL in your code) correct?

The issue could also arise for other reasons. Would you be able to point us to the repo, or at least having the config.toml file might help us?


Thank you very much for the very quick reply,

of course you get everything. As I said, I have not changed the code at all. I had the problem once when I inserted new empty lines to make the code a bit clearer. When I reverted that everything worked again.

Here is the repo:

Ok, great.

Just to be clear, do you still need any support on this?


yes in any case, because I do not know why this happens repeatedly, although I do not change the code.

Upon checking the config file from the repository you provided, it appears to be correctly formatted.

From what I gather, you mentioned an issue that occured after adding an empty line in the .py file. However, simply adding an empty line in the main Py file,, shouldn’t typically introduce any bugs.

A practical approach would be to:

  • Revert to a previous version of your repo, to a point when everything was working as expected.
  • Then, compare the two versions to pinpoint any differences.
  • Additionally, the traceback you shared earlier indicates a KeyError when attempting to load a model via joblib. Could you please double-check if the path to the model file is accurate?


That is the problem, this caused the error:

Can you try rebooting the app and see whether that fixes it?


1 Like

It was a versioning problem. Now everything works again after rebooting.

Thanks for the very fast and helpful support!

Glad it’s now working!

Happy Streamlitin’!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.