added try for sql connect

This commit is contained in:
2021-11-02 10:42:00 -04:00
parent 679bfadbb6
commit d5b9ec4482

View File

@@ -145,8 +145,17 @@ dbconfig = {
'raise_on_warnings': True
}
logger.debug("Starting SQL query for LDAPUsers")
cnx = mysql.connector.connect(**dbconfig)
logger.debug("SQL Connection: {0}".format(cnx))
try:
cnx = mysql.connector.connect(**dbconfig)
logger.debug("SQL Connection: {0}".format(cnx))
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
logger.critical("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
logger.critical("Database does not exist")
else:
logger.critical(err)
exit(3)
cursor = cnx.cursor()
query = ("SELECT * FROM LDAPUsers")
logger.debug("Query: {0}".format(query))