python 连接mysql 时,connect 出现错误,怎么解决

2024-11-15 19:59:23
推荐回答(1个)
回答1:

# -*- coding: utf-8 -*-
import MySQLdb
from MySQLdb.cursors import DictCursor

def catch_2006(func):
"""
To catch MySQL Error 2006 ('Server has gone away')
"""

def _(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except MySQLdb.Error, e:
print __file__, e

...