Python mysql.connector.errorcode.ER_ACCESS_DENIED_ERROR Examples
The following are 3
code examples of mysql.connector.errorcode.ER_ACCESS_DENIED_ERROR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mysql.connector.errorcode
, or try the search function
.
Example #1
Source File: mariadb.py From carpe with Apache License 2.0 | 6 votes |
def __init__(self, user, password, database=None, verbose=LOG_OFF): # passwd = input("Password > ") # passwd = password self._v = verbose if database is not None: self.database = database try: self.conn = maria.connect(user=user, password=password, database=self.database) except maria.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with your user name or password") elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) else: try: self.conn = maria.connect(user=user, password=password) except maria.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with your user name or password") else: print(err)
Example #2
Source File: utilities.py From Ithemal with MIT License | 5 votes |
def create_connection(database=None, user=None, password=None, port=None): args = {} option_files = list(filter(os.path.exists, map(os.path.abspath, map(os.path.expanduser, [ '/etc/my.cnf', '~/.my.cnf', ])))) if option_files: args['option_files'] = option_files if database: args['database'] = database if user: args['user'] = user if password: args['password'] = password if port: args['port'] = port cnx = None try: cnx = mysql.connector.connect(**args) except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print("Something is wrong with your user name or password") elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) return cnx
Example #3
Source File: dbConnect.py From dbConnect with Mozilla Public License 2.0 | 4 votes |
def connect(self): """ Creates connection to database, sets connection and cursor Connection to database can be loosed, if that happens you can use this function to reconnect to database """ if self.engine == "mysql": found_connector = False try: # Import official mysql connector if exists import mysql.connector as mysql_module from mysql.connector import errorcode found_connector = True except ImportError: pass if not found_connector: # Check MySQLdb as secondary option try: import MySQLdb as mysql_module except ImportError: raise ValueError( 'Please, install mysql-connector or mysqlclient module before using this library.' ) # Connect to db try: self.connection = mysql_module.connect(**self.settings) except mysql_module.Error as err: if found_connector: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: raise ValueError("Wrong credentials, ACCESS DENIED") elif err.errno == errorcode.ER_BAD_DB_ERROR: raise ValueError( "Database %s does not exists" % (self.settings['database']) ) else: raise ValueError(err) # @TODO Add detailed errors for MySQLdb raise err elif self.engine == "postgres": try: import psycopg2 except ImportError: raise ValueError( 'Please, install psycopg2 module before using plugin.' ) self.connection = psycopg2.connect(**self.settings) else: raise NotImplementedError( "Database engine %s not implemented!" % self.engine ) self.cursor = self.connection.cursor()