Update database.py - pymysql.err.InterfaceError: (0,”) error (#325)

check if the connection exists, and reconnect if disconnected.
This commit is contained in:
cpanel10x 2023-12-25 01:03:52 +07:00 committed by GitHub
parent 682d7db2d6
commit b3cabe3c3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -258,6 +258,7 @@ class MySQL:
self.con = pymysql.connect(
host=MYSQL_HOST, user=MYSQL_USER, passwd=MYSQL_PASS, db="ytdl", charset="utf8mb4"
)
self.con.ping(reconnect = True)
except Exception:
logging.warning("MySQL connection failed, using fake mysql instead.")
self.con = FakeMySQL()