KeyError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 371, in __getitem__
    return self._getitem(widget_id, key)
  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 411, in _getitem
    raise KeyError
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 354, in _run_script
    exec(code, module.__dict__)
  File "/app/master_thesis/streamlit_app.py", line 139, in <module>
    if  st.session_state['answer'] in realans:
  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 667, in __getitem__
    return state[key]
  File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/state/session_state.py", line 373, in __getitem__
    raise KeyError(_missing_key_error_message(key))
KeyError: 'st.session_state has no key "answer". Did you forget to initialize it?'



[client] Connecting...
 st.session_state['answer'] = ''

 if  st.session_state['answer'] in realans:
        answerStat = "correct"
    elif st.session_state['answer'] not in realans:
        answerStat = "incorrect"

Hi @Nikul_G,

I added a realans list with an empty string and it seems to work as expected (see below)

import streamlit as st

st.session_state['answer'] = ''!

st.write(st.session_state)

realans = ['', 'abc', 'edf']

if  st.session_state['answer'] in realans:
    answerStat = "correct"
elif st.session_state['answer'] not in realans:
    answerStat = "incorrect"

st.write(st.session_state)
st.write(answerStat)

Screen Shot 2021-10-05 at 5.20.33 PM

the Streamlit version I am using is1.0 (launched today! :partying_face:), I also tried on 0.89 (what I had installed prior to updating.

can you share the GitHub repo you’re deploying from?

Happy Streamlit-ing!
Marisa

1 Like

here is my repo Master_Thesis/streamlit_appcopy.py at main · NikulGoyani369/Master_Thesis · GitHub
and I do not know how to pass the openAI api key?
please let me know if you know.

Secrets can be passed via the Streamlit Cloud secrets management functionality

https://docs.streamlit.io/en/stable/deploy_streamlit_app.html#secrets-management

Best,
Randy

3 Likes

Thank you, @randyzwitch, I will try with secrets management functionality.

1 Like

2 posts were split to a new topic: Key error: sklearn.preprocessing

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