Hello All,
I have successfully built an Attendance App on my Windows system in Pycharm. This App simply collects a student’s email address and has a submit button. Once the student types their email and hits submit, the App creates a MySQL table if not exist and changes the student’s status from 0 to 1 in the table. While printing out a successful message for the student. And if a wrong email is submitted, a message is printed out to correct it.
Very simple and straightforward.
The App works perfectly on my local machine, using
connection = mysql.connector.connect(**st.secrets["mysql"])
I have the .streamlit/secrets.toml
file as well as the secrets section of the App with the right database name, username, password and so on.
I read and re-read and do every single step listed in the streamlit doc for connecting MySQL databases and it works perfectly on my system, but fails to deploy on streamlit cloud, with message:
Can't connect to MySQL server on 'localhost:3306' (99)
Please see the detailed log below and help me point out what could be wrong. I really need this for my students and I am frustrated at the failures to deploy.
[22:08:23] 📦 Processed dependencies!
2022-06-06 22:10:40.801 Uncaught app exception
Traceback (most recent call last):
File "/home/appuser/venv/lib/python3.9/site-packages/mysql/connector/connection_cext.py", line 246, in _open_connection
self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Can't connect to MySQL server on 'localhost:3306' (99)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/scriptrunner/script_runner.py", line 554, in _run_script
exec(code, module.__dict__)
File "main.py", line 21, in <module>
connection = mysql.connector.connect(**st.secrets["mysql"])
File "/home/appuser/venv/lib/python3.9/site-packages/mysql/connector/__init__.py", line 272, in connect
return CMySQLConnection(*args, **kwargs)
File "/home/appuser/venv/lib/python3.9/site-packages/mysql/connector/connection_cext.py", line 94, in __init__
self.connect(**kwargs)
File "/home/appuser/venv/lib/python3.9/site-packages/mysql/connector/abstracts.py", line 1052, in connect
self._open_connection()
File "/home/appuser/venv/lib/python3.9/site-packages/mysql/connector/connection_cext.py", line 251, in _open_connection
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (99)