当前位置: 首页>>代码示例>>Python>>正文


Python errorcode.ER_ACCESS_DENIED_ERROR属性代码示例

本文整理汇总了Python中mysql.connector.errorcode.ER_ACCESS_DENIED_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Python errorcode.ER_ACCESS_DENIED_ERROR属性的具体用法?Python errorcode.ER_ACCESS_DENIED_ERROR怎么用?Python errorcode.ER_ACCESS_DENIED_ERROR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在mysql.connector.errorcode的用法示例。


在下文中一共展示了errorcode.ER_ACCESS_DENIED_ERROR属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from mysql.connector import errorcode [as 别名]
# 或者: from mysql.connector.errorcode import ER_ACCESS_DENIED_ERROR [as 别名]
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) 
开发者ID:dfrc-korea,项目名称:carpe,代码行数:26,代码来源:mariadb.py

示例2: create_connection

# 需要导入模块: from mysql.connector import errorcode [as 别名]
# 或者: from mysql.connector.errorcode import ER_ACCESS_DENIED_ERROR [as 别名]
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 
开发者ID:ithemal,项目名称:Ithemal,代码行数:33,代码来源:utilities.py

示例3: connect

# 需要导入模块: from mysql.connector import errorcode [as 别名]
# 或者: from mysql.connector.errorcode import ER_ACCESS_DENIED_ERROR [as 别名]
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() 
开发者ID:mastizada,项目名称:dbConnect,代码行数:54,代码来源:dbConnect.py


注:本文中的mysql.connector.errorcode.ER_ACCESS_DENIED_ERROR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。