Ich hole Benutzer -ID und Kennwortformularzugriff auf DB. Dann werden die Daten verwendet, um sich im Streamlit-Authenticator anzumelden.import os
from dbfread import DBF
import configparser
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import time
import pyodbc
import streamlit_authenticator as stauth
import bcrypt
# Pobranie ścieżki do pliku konfiguracyjnego (w katalogu skryptu)
config_path = os.path.join(os.getcwd(), "config.ini")
# Sprawdzenie, czy plik istnieje
if not os.path.exists(config_path):
print(f"Błąd: Plik konfiguracyjny nie znaleziony! Sprawdź, czy istnieje: {config_path}")
else:
# Wczytanie pliku konfiguracji
config = configparser.ConfigParser()
config.read(config_path)
# Wczytanie pliku konfiguracyjnego
config = configparser.ConfigParser()
config.read("config.ini")
# Pobranie kodu firmy
fkod = config["Kod"]["kodfirmy"]
dbpath = config["Sciezki"]["dba"]
print(dbpath)
# Połączenie z bazą danych Access
conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
f'DBQ={dbpath};'
)
conn = pyodbc.connect(conn_str)
cursor = conn.cursor()
# Pobranie użytkowników
cursor.execute("SELECT user_id, hashed_password FROM users")
users = cursor.fetchall()
# Przetworzenie danych do formatu Streamlit Authenticator
credentials = {"usernames": {user[0]: {'password': user[1]} for user in users}}
# Inicjalizacja Streamlit Authenticator
authenticator = stauth.Authenticate(
credentials,
"some_cookie_name",
"some_key",
cookie_expiry_days=30
)
name, authentication_status, username = authenticator.login(
fields={
'Form name': 'Login',
'Username': 'name',
'Password': 'password',
}
)
if authentication_status:
st.write(f'Witaj *{name}*!')
authenticator.logout('Wyloguj', 'main')
elif authentication_status is False:
st.error('Nieprawidłowa nazwa użytkownika/hasło')
elif authentication_status is None:
st.warning('Wprowadź nazwę użytkownika i hasło')
< /code>
Was ich bekomme, folgt die Ausnahme: < /p>
streamlit_authenticator.utilities.exceptions.LoginError: User not authorized
Traceback:
File "C:\py\app.py", line 59, in
name, authentication_status, username = authenticator.login(
~~~~~~~~~~~~~~~~~~~^
fields={
^^^^^^^^
......
}
^
)
^
File "C:\Users\fwoda\AppData\Local\Programs\Python\Python313\Lib\site-packages\streamlit_authenticator\views\authentication_view.py", line 333, in login
self.authentication_controller.login(token=token)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "C:\Users\fwoda\AppData\Local\Programs\Python\Python313\Lib\site-packages\streamlit_authenticator\controllers\authentication_controller.py", line 265, in login
return self.authentication_model.login(username, password, max_concurrent_users,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
max_login_attempts, token, single_session,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
callback)
^^^^^^^^^
File "C:\Users\fwoda\AppData\Local\Programs\Python\Python313\Lib\site-packages\streamlit_authenticator\models\authentication_model.py", line 432, in login
raise LoginError('User not authorized')
< /code>
In der Zugriffsdatenbank gibt es einen Benutzer: Benutzer1. < /p>
Ich kann nicht erraten, wo das Problem mit Authenticator ist. Könnten Sie beraten?
Python, Streamlit-Authenticator-Benutzer nicht autorisiert. Login nicht in der Lage ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post