diff --git a/seafile-ldap.py b/seafile-ldap.py index 0282a34..d7f095b 100644 --- a/seafile-ldap.py +++ b/seafile-ldap.py @@ -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))