Page 1 of 1

Hook PyMSQL errors

Posted: Thu Jun 30, 2016 3:36 pm
by decompile
Hey, How can I hook some PyMYSQL errors so I can lets say let it reconnect- or just print a server message with (MySQL Connection Lost.)?

I just found that my server is rare'ly just timing out, which gives some error messages in console:

Code: Select all

pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')


Code: Select all

TimeoutError: [WinError 10060] Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat


Code: Select all

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'xx' ([Errno 11002] getaddrinfo failed)")


Do I need to modify the pymysql package or can I do it with an own written script.

Re: Hook PyMSQL errors

Posted: Thu Jun 30, 2016 4:01 pm
by Ayuto
Just catch the exceptions using try/except.