I have looked at the MySQL issues posted here but I am unable to find a resolution. I have created my app using codespaces on the browser and i dont have a local version of my app running on my computer and only using Streamlit cloud. It seems I am making a mistake with the DSQL configurattion information and I cannot figure out what it is.
Below is my code, the requirements.txt file and secrets.toml which I have added to the settings under the secrets tab.
Python Code
import streamlit as st
import sqlalchemy
Everything is accessible via the st.secrets dict:
st.write(“DB username:”, st.secrets[“db_username”])
st.write(“DB password:”, st.secrets[“db_password”])
st.write(st.secrets)
Initialize connection.
#conn = st.connection(‘mysql’, type=‘sql’)
conn = st.experimental_connection(‘dbx’, type=‘sql’)
Perform query.
#df = conn.query(‘SELECT * from Individual;’, ttl=600)
dbxx = conn.query(‘SELECT * from Individual’)
Print results.
#for row in df.itertuples():
st.write(f"{row.FirstName} has a :{row.Ethnicity}:")
st.dataframe(dbxx)
SECRETS in settings of app
[connections.dbx]
type=“sql”
dialect=“mysql”
username=“xxxxxx”
password=“XXXXXXXXX”
host=“mysql-xxxxxxxxxxx.us-east-1.rds.amazonaws.com”
port=3306 # Port number
database=“DivIndexXXXX”
Results and Error :
DB username: xxxxx
DB password: XXXXXXXXX
{'type': 'sql', 'dialect': 'mysql', 'db_username': 'xxxxx', 'db_password': 'XXXXXX', 'host': 'mysql-xxxxxxxxxxxxxx.us-east-1.rds.amazonaws.com', 'port': 3306, 'database': 'DivIndexXXXX'}
StreamlitAPIException: Missing SQL DB connection configuration. Did you forget to set this in secrets.toml
or as kwargs to st.connection
?
Traceback:
File "/workspaces/Streamlit/streamlit_app.py", line 111, in <module>
conn = st.experimental_connection('dbx', type='sql')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^