Python MySQLdb.DatabaseError() Examples

The following are code examples for showing how to use MySQLdb.DatabaseError(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: ScrapyNews   Author: chenxilinsidney   File: pipelines.py    (license) View Source Project 6 votes vote down vote up
def open_spider(self, spider):
        """
        called when spider is opened.
        do something before pipeline is processing items.
        example: do settings or create connection to the database.
        """
        try:
            spider.logger.debug("trying to connect mysql")
            self.db = MySQLdb.connect(host=self.mysql_ip, port=self.mysql_port,
                                      user=self.mysql_user,
                                      passwd=self.mysql_password,
                                      db=self.mysql_database)
        except MySQLdb.DatabaseError:
            spider.logger.error("can not connect mysql")
            raise MySQLdb.DatabaseError
        return 
Example 2
Project: pyExamples   Author: mike-zhang   File: restoreTableFromCSV_test1.py    (license) View Source Project 5 votes vote down vote up
def execute(self,sql):
        '''exec sql insert'''
        ret = 0
        try:
            cursor = self.conn.cursor()
            ret = cursor.execute(sql)
        except (AttributeError,MySQLdb.OperationalError, MySQLdb.DatabaseError):            
            logger.error(traceback.format_exc())
            logger.error("sql:{0}".format(sql))
            self.connect()
            if self.conn:
                cursor = self.conn.cursor()
                ret = cursor.execute(sql)
        return ret