我需要捕获一个特定的OperationalError异常。异常文本使用错误代码2006。库在MySQLdb.constants.CR.SERVER_GONE_ERROR = 2006中定义错误代码.
如何从异常获取错误代码?
当我检查MySQLdb._mysql_exceptions时,有一个OperationalError异常的定义,但是它没有构造函数或关于如何访问异常错误代码的描述。
发布于 2017-12-22 15:12:38
可以捕获错误号,如下所示:
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:
pass
else:
raise参考资料:https://www.programcreek.com/python/example/2584/MySQLdb.OperationalError
https://stackoverflow.com/questions/43663130
复制相似问题