Forums

mysql flask are not working for me could anyone help?

ok so i have my web page and any time I try and run this code:

mydb = mysql.connector.connect( host="fooddude.mysql.pythonanywhere-services.com", user=usql, password=psql, database="fooddude$website" ) mycursor = mydb.cursor()

it doesn't work and here are the logs

.server.log:

"

2022-01-05 01:47:51 Wed Jan 5 01:47:51 2022 - received message 0 from emperor

2022-01-05 01:47:51 SIGINT/SIGQUIT received...killing workers...

2022-01-05 01:47:52 worker 1 buried after 1 seconds

2022-01-05 01:47:52 goodbye to uWSGI.

2022-01-05 01:47:52 VACUUM: unix socket /var/sockets/fooddude.pythonanywhere.com/socket removed.

2022-01-05 01:47:55 *** Starting uWSGI 2.0.19.1 (64bit) on [Wed Jan 5 01:47:54 2022] ***

2022-01-05 01:47:55 compiled with version: 9.3.0 on 27 May 2021 21:02:35

2022-01-05 01:47:55 os: Linux-5.8.0-1041-aws #43~20.04.1 SMP Wed Aug 4 15:15:42 UTC 2021

2022-01-05 01:47:55 nodename: green-liveweb3

2022-01-05 01:47:55 machine: x86_64

2022-01-05 01:47:55 clock source: UNIX

2022-01-05 01:47:55 pcre jit disabled

2022-01-05 01:47:55 detected number of CPU cores: 4

2022-01-05 01:47:55 current working directory: /home/fooddude

2022-01-05 01:47:55 detected binary path: /usr/local/bin/uwsgi

2022-01-05 01:47:55 *** dumping internal routing table ***

2022-01-05 01:47:55 [rule: 0] subject: path_info regexp: .svgz$ action: addheader:Content-Encoding:gzip

2022-01-05 01:47:55 [rule: 1] subject: path_info regexp: /.well-known/acme-challenge/ action: continue:

2022-01-05 01:47:55 [rule: 2] subject: path_info regexp: ^/ action: basicauth:Default Realm,/etc/uwsgi/fooddude.pythonanywhere.com.htpasswd

2022-01-05 01:47:55 *** end of the internal routing table ***

2022-01-05 01:47:55 chdir() to /home/fooddude/

2022-01-05 01:47:55 your processes number limit is 128

2022-01-05 01:47:55 your memory page size is 4096 bytes

2022-01-05 01:47:55 detected max file descriptor number: 123456

2022-01-05 01:47:55 building mime-types dictionary from file /etc/mime.types...

2022-01-05 01:47:55 567 entry found

2022-01-05 01:47:55 lock engine: pthread robust mutexes

2022-01-05 01:47:55 thunder lock: disabled (you can enable it with --thunder-lock)

2022-01-05 01:47:55 uwsgi socket 0 bound to UNIX address /var/sockets/fooddude.pythonanywhere.com/socket fd 3

2022-01-05 01:47:55 Python version: 3.9.5 (default, May 27 2021, 19:45:35) [GCC 9.3.0]

2022-01-05 01:47:55 *** Python threads support is disabled. You can enable it with --enable-threads ***

2022-01-05 01:47:55 Python main interpreter initialized at 0x5620ad251c90

2022-01-05 01:47:55 your server socket listen backlog is limited to 100 connections

2022-01-05 01:47:55 your mercy for graceful operations on workers is 60 seconds

2022-01-05 01:47:55 setting request body buffering size to 65536 bytes

2022-01-05 01:47:55 mapped 334256 bytes (326 KB) for 1 cores

2022-01-05 01:47:55 *** Operational MODE: single process ***

2022-01-05 01:47:55 initialized 38 metrics

2022-01-05 01:47:55 WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x5620ad251c90 pid: 1 (default app)

2022-01-05 01:47:55 *** uWSGI is running in multiple interpreter mode ***

2022-01-05 01:47:55 gracefully (RE)spawned uWSGI master process (pid: 1)

2022-01-05 01:47:55 spawned uWSGI worker 1 (pid: 2, cores: 1)

2022-01-05 01:47:55 metrics collector thread started

2022-01-05 01:47:55 spawned 2 offload threads for uWSGI worker 1

2022-01-05 01:48:08 announcing my loyalty to the Emperor...

"

any help would be nice and thank you and have a good rest of your day.

Check your error log, not a server one.

here is the error log

2022-01-05 23:03:17,685: Error running WSGI application

2022-01-05 23:03:17,693: mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user ''@'10.0.0.151' (using password: NO)

2022-01-05 23:03:17,693: File "/var/www/fooddude_pythonanywhere_com_wsgi.py", line 16, in <module>

2022-01-05 23:03:17,694: from flask_app import app as application # noqa

2022-01-05 23:03:17,694:

2022-01-05 23:03:17,694: File "/home/fooddude/site/flask_app.py", line 21, in <module>

2022-01-05 23:03:17,694: mydb = mysql.connector.connect(

2022-01-05 23:03:17,694:

2022-01-05 23:03:17,694: File "/usr/local/lib/python3.9/site-packages/mysql/connector/init.py", line 271, in connect

2022-01-05 23:03:17,694: return MySQLConnection(args, *kwargs)

2022-01-05 23:03:17,694:

2022-01-05 23:03:17,695: File "/usr/local/lib/python3.9/site-packages/mysql/connector/connection.py", line 107, in init

2022-01-05 23:03:17,695: self.connect(**kwargs)

2022-01-05 23:03:17,695:

2022-01-05 23:03:17,695: File "/usr/local/lib/python3.9/site-packages/mysql/connector/abstracts.py", line 985, in connect

2022-01-05 23:03:17,695: self._open_connection()

2022-01-05 23:03:17,695:

2022-01-05 23:03:17,695: File "/usr/local/lib/python3.9/site-packages/mysql/connector/connection.py", line 310, in _open_connection

2022-01-05 23:03:17,695: self._do_auth(self._user, self._password,

2022-01-05 23:03:17,696:

2022-01-05 23:03:17,696: File "/usr/local/lib/python3.9/site-packages/mysql/connector/connection.py", line 219, in _do_auth

2022-01-05 23:03:17,696: self._auth_switch_request(username, password)

2022-01-05 23:03:17,696:

2022-01-05 23:03:17,696: File "/usr/local/lib/python3.9/site-packages/mysql/connector/connection.py", line 276, in _auth_switch_request

2022-01-05 23:03:17,696: raise errors.get_exception(packet)

2022-01-05 23:03:17,696: *********

2022-01-05 23:03:17,696: If you're seeing an import error and don't know why,

2022-01-05 23:03:17,696: we have a dedicated help page to help you debug:

2022-01-05 23:03:17,697: https://help.pythonanywhere.com/pages/DebuggingImportError/

2022-01-05 23:03:17,697: *********

I fixed it but now I have the database username and password in plain text. would this be bad for some cases?

It depends where do you have it. If it's in some public repo on github, it's bad. If it's in ~/.my.cnf it's as secure as your account. See https://help.pythonanywhere.com/pages/SecuringYourAccount/