I am trying to run my project and getting: ValueError: Location must be one of 'main' or 'sidebar' or 'unrendered'

The app is run locally & running Streamlit, version 1.38.0, Python 3.12.6

from src.schemas import Configuration

import streamlit as st

from src.schemas.engine import Engine

from PIL import Image

from streamlit_extras import add_vertical_space as avs

import streamlit_authenticator as stauth

print("streamlit version: ", st.__version__)

st.set_page_config(
    page_title="Demo: Page", # Title of the page in your browser tab
    layout="wide" # Wide mode
)

#-- adding streamlit authentication

config = Configuration()

streamlit_credentials = config.streamlit_credentials

print("streamlit_credentials: ")

print(streamlit_credentials)

authenticator = stauth.Authenticate(
    streamlit_credentials['credentials'],
    streamlit_credentials['cookie']['name'],
    streamlit_credentials['cookie']['key'],
    streamlit_credentials['cookie']['expiry_days'],

)


name, authentication_status, username = authenticator.login('Login', 'main')

if authentication_status == False:
    st.error("Username/password is incorrect")

if authentication_status == None:
    st.warning("Please enter your username and password")

if authentication_status == False:
    st.error('Username/password is incorrect')
elif authentication_status == None:
    st.warning('Please enter your username and password')
elif authentication_status:
    authenticator.logout('Logout', 'main')
    st.sidebar.title("Welcome " + name)
    with open('app/src/assets/css/app.css')as f:
        st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html = True)

Hi @Brandy, welcome to the forum!

Would you mind editing your post to put all your code between ```'s, so that it’s formatted as a code block, like this:

import streamlit as st

if foo == bar:
    st.write("Yes")

As to the specific error, it’s a little hard to know for certain, but it looks like the way you’re using authenticator.login and logout is not correct – you can see the README here GitHub - mkhorasani/Streamlit-Authenticator: A secure authentication module to manage user access in a Streamlit application. – it looks like the first argument to those functions is the location, which needs to be 'main' in your case, but you’re passing 'Login' and 'Logout'

Hi blackary, Thank you for your response as this was code I got from another colleague’s github I am trying to run locally. He pretty much said all that is required is to run the following:

python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
streamlit run app/main.py

…after creating .env file

I did not have a list of dependencies either.

I will take a look, you spotted that fast! Thanks

You’re welcome! My guess is that the app used to use an older version of streamlit-authenticator, before the login() and logout() behavior changed 0.2.4 login() is breaking - Throws Nonsensical Error on Login Button Location · Issue #109 · mkhorasani/Streamlit-Authenticator · GitHub

You can probably either change requirements.txt to use an older version of that library, or update the code to match what the new version expects.

1 Like

Thanks blackary, I have another issue related to authentication do i need to open a new case?
it is similar to this: Streamlit authentication problems - can't log in - #3 by clarac1996 can i share my code and results here?

You’re welcome to create a new forum post, but if it was me, I would first look at the README and the issues in the Streamlit-Authenticator github repository and see if that’s helpful. If you think it’s a bug with the Streamlit-Authenticator package, you might want to post it as a new issue on there. But, you’re also welcome to post a new topic on the forum about it, and you will probably get some help on here as well.

1 Like

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