Home > Mobile >  streamlit Authenticate.__init__() got multiple values for argument 'cookie_expiry_days'
streamlit Authenticate.__init__() got multiple values for argument 'cookie_expiry_days'

Time:07-31

I'm building a basic streamlit app. In order to validate user credentials, I'm using the authentification module of streamlit. Only one problem, the code does not work !

ERROR

TypeError: Authenticate.init() got multiple values for argument 'cookie_expiry_days'

Traceback:

File "C:\Users_M92\Desktop\Coding\Python\Projects\Personal1\venv\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 557, in _run_script exec(code, module.dict)

File "app.py", line 23, in authenticator = stauth.Authenticate(names, usernames, hashed_passwords,

By the way, I used the same code described here in the official documentation :

CODE

import streamlit as st
import streamlit_authenticator as stauth

names = ['John Smith', 'Rebecca Briggs']
usernames = ['jsmith', 'rbriggs']
passwords = ['123', '456']

hashed_passwords = stauth.Hasher(passwords).generate()

authenticator = stauth.Authenticate(names, usernames, hashed_passwords,
    'some_cookie_name', 'some_signature_key', cookie_expiry_days=30)

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

if authentication_status:
    authenticator.logout('Logout', 'main')
    st.write('Welcome *%s*' % (name))
    st.title('Some content')
elif authentication_status == False:
    st.error('Username/password is incorrect')
elif authentication_status == None:
    st.warning('Please enter your username and password')

if st.session_state['authentication_status']:
    st.write('Welcome *%s*' % (st.session_state['name']))
    st.title('Some content')
elif st.session_state['authentication_status'] == False:
    st.error('Username/password is incorrect')
elif st.session_state['authentication_status'] == None:
    st.warning('Please enter your username and password')

When I removed the argument cookie_expiry_days=30, I get this error instead :

TypeError: list indices must be integers or slices, not str

File"C:\Users_M92\Desktop\Coding\Python\Projects\Personal1\venv\lib\site-packages\streamlit_authenticator\authenticate.py",line 36, in __init__self.credentials['usernames'] = {key.lower(): value for key, value in credentials['usernames'].items()}

Do you have any idea why I keep getting these errors ?

CodePudding user response:

hashed_passwords = stauth.hasher(passwords).generate() # Changed .Hasher to .hasher

authenticator = stauth.authenticate(names, usernames, hashed_passwords,
    'some_cookie_name', 'some_signature_key', cookie_expiry_days=30) # Changed .Authenticate to .authenticate

Your code should be up and running now.

  • Related