「查詢過程中丟失連接到MySQL服務器的」我使用如何捕捉特定的錯誤
def mysql_handling(string):
global cursor
while True:
try:
cursor.execute(string)
if 'SELECT' not in string:
db.commit()
break
except MySQLdb.MySQLError:
cursor.close()
print 'something went wrong!!'
time.sleep(1)
cursor = get_cursor()
如果要在連接失敗重新進行查詢,但我ONLY要重新連接時,我有錯誤「查詢期間與MySQL服務器失去連接」。 (否則mysql_handling函數進入無限循環)
那麼我應該用什麼來代替'除了MySQLdb.MySQLError:'?
謝謝你的回答! – Lazykiddy 2013-03-05 13:35:20