Issue
I've written this code for the homepage of my streamlit app:
import streamlit as st
from streamlit_login_auth_ui.widgets import __login__
__login__obj = __login__(auth_token = st.secrets['courier_auth_token'],
company_name = "The Suite",
width = 200, height = 250,
logout_button_name = 'Logout',
hide_menu_bool = False,
hide_footer_bool = True,
lottie_url = 'https://assets2.lottiefiles.com/packages/lf20_jcikwtux.json'
)
LOGGED_IN = __login__obj.build_login_ui()
if LOGGED_IN != True:
with open('style3.css') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
if LOGGED_IN == True:
st.sidebar.success('Select a page above')
username = __login__obj.get_username()
if username =='Liscivia':
def show_download_Json():
with open('_secret_auth_.json') as f:
st.download_button('Download Json', f)
show_download_Json()
I'd need to call the get_username() function to retrieve my user as an admin to be able to download a file. This is the repo that I used to create the login form: https://github.com/GauriSP10/streamlit_login_auth_ui/ and this is an issue that has been resolved regarding the function: https://github.com/GauriSP10/streamlit_login_auth_ui/issues/2 , this file also shows an example of the function in use: https://github.com/GauriSP10/streamlit_login_auth_ui/blob/main/app.py
The import of the function fails though, what could be the problem given that the library is correctly installed and updated to the latest version (0.2.0)?
This is the error I get:
AttributeError: '__login__' object has no attribute 'get_username'
Traceback:
File "C:\Users\gianm\anaconda3\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 562, in _run_script
exec(code, module.__dict__)
File "C:\Users\gianm\Py_Projects\Indicator_Suite\🏠Home.py", line 36, in <module>
username = __login__obj.get_username()
Also trying updating python to 3.11 but didn't work.
Solution
The code where get_username()
is implemented is not yet updated in pypi. You can install the latest code by downloading the whole repo with git clone command.
Step 1
From command line.
git clone https://github.com/GauriSP10/streamlit_login_auth_ui.git
Step 2
cd streamlit_login_auth_ui
Step 3
Install the latest code.
pip install .
The last character is dot.
Run your streamlit app again and it will return a username.
Sample code
LOGGED_IN = __login__obj.build_login_ui()
if LOGGED_IN:
st.markdown("Your Streamlit Application Begins here!")
username = __login__obj.get_username()
st.write(username)
Output
image 1
image 2
Get username
if LOGGED_IN:
if not st.session_state['LOGOUT_BUTTON_HIT']:
fetched_cookies = __login__.cookies
if '__streamlit_login_signup_ui_username__' in fetched_cookies.keys():
username = fetched_cookies['__streamlit_login_signup_ui_username__']
st.write(username)
Answered By - ferdy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.