Skip to content Skip to sidebar Skip to footer

Python-mysqldb, How Do You Access The Exception Error-code In `operationalerror`?

I need to catch a specific OperationalError exception. The exception text uses the error-code 2006. The library defines the error-codes at MySQLdb.constants.CR.SERVER_GONE_ERROR =

Solution 1:

You can catch the error number like the following:

try:
            # Adding field 'Bug.bize_size_tag_name'
            db.add_column('search_bug', 'bize_size_tag_name', orm['search.bug:bize_size_tag_name'])
except MySQLdb.OperationalError, errorCode:
            if errorCode[0] == 1060:
                passelse:
                raise

Reference: https://www.programcreek.com/python/example/2584/MySQLdb.OperationalError

Post a Comment for "Python-mysqldb, How Do You Access The Exception Error-code In `operationalerror`?"