I am creating an always-on task to process queued items and am not successful in connecting to MySQL. I get the following error:
1045 (28000): Access denied for user 'user'@'10.0.0.207' (using password: NO) (error thrown at `if db_connection.is_connected():`)
.
def process_queue():
config = {
'user': DB_USER,
'password': DB_PWD,
'host': DB_HOST,
'database': DB,
}
try:
db_connection = mysql.connector.connect(**config)
db_cursor = db_connection.cursor()
sql = """Select * FROM webhooks where queued = %s"""
db_cursor.execute(sql, [1])
webhooks = db_cursor.fetchall()
db_cursor.close()
except mysql.connector.Error as error:
print("Failed to get records: {}".format(error))
finally:
if db_connection.is_connected():
db_connection.close()
print("MySQL connection is closed")
... do something
else:
... do something else
time.sleep(60)
I run it by adding an endpoint in flask and simply posting to it from Postman and the function runs perfectly, however, as an always-on task it throws the aforementioned error and even states that I'm not using a password when I am in the config var. Was hoping to use the functions interchangeably (flask and console), but unable at this point. Any help is greatly appreciated!