What does this error mean

i was wondering what this error meant.
it seems to be something about the key, but if i change it it will say the is one with that key


(dont tell me its a coincidence, i tried many things :))

hi henosBot,

This is probably because you are trying to make several text_inputs with the same label, in this case the label “User ID”. Is the statement user_id = id.text_input("User ID") in a loop by any chance? If you only need one user input, you need to move it out of this loop.

If you need multiple inputs with the same label, you need to specify a “key” for each input, an example could be

for i in range(3):
    user_id = st.text_input("User ID", key=i)

although in many cases you would want to change the label instead.

3 Likes

this is my code:

import streamlit as st
import tools
import time

st.title('henos Roll Taking system')
markdown = st.empty()
markdown.markdown(tools.viewBeforeLogin)
id = st.empty()
passw = st.empty()
button = st.empty()
loggedin = False
while not loggedin:
    user_id = id.text_input('User ID')
    user_pass = passw.text_input('Password')
    login = button.button('Login')
    if login:
        with st.spinner('Logging in ...'):
            time.sleep(0.5)
            tf, reason = tools.auth(user_id, user_pass)
        if tf is False and reason == 'id':
            incor = st.error('I could not find a user with that id')
            try_again = button.button('Try again')
            if try_again:
                incor.empty()
                continue
        elif tf is False and reason == 'pass':
            incor = st.error('Incorrect Password')
            try_again = button.button('Try again')
            if try_again:
                incor.empty()
                continue
        else:
            id.empty()
            passw.empty()
            button.empty()
            markdown.empty()
            loggedin = True

success = st.empty()
success.success('Logged in successfully')
time.sleep(2)
success.empty()

markdown.markdown(tools.viewAfterLogin)

mark = st.empty()
ctrl = st.empty()
markb = mark.button('Mark Roll')
ctrlb = ctrl.button('Control Panel')

Hi henosBot,

I think a good first step would be to replace the while statement with an if statement, and then make use of st.stop() to make sure the user does not go further unless logged in.

You will likely also need to use the session state ‘hack’ to persist the login - I would recommend you search around the forum for examples on session state and authentication.