0

I am using Heroku and a Clear DB for a python script I made. The script seems to work if after the bot is deployed in Discord, it will collect the information of a user and reply back to them after it collects a certain number of entries. However, If there are no messages during a minute's time, I get the following error in my terminal:

 File "C:\Users\Chase The Great\Anaconda3\lib\site-packages\mysql\connector\network.py", line 251, in recv_plain
    raise errors.InterfaceError(errno=2013)
mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query

Is there a way to make the connection active again or make the connection indefinite?

I am using the module mysql.connector for communicating to the DB. Here is some of my code if there is an inaccuracy for how I am writing it:

async def on_message(message):
    sql_users_info = "SELECT * FROM host_server.user_levels;"
    mycursor.execute(sql_users_info)
    user_info = mycursor.fetchall()
    user_names = []
    user_exp = []
    for i in user_info:
        user_names.append(i[0])
        user_exp.append(i[1])
    await update_data(user_names, message.author)
    await add_experience(user_names, message.author, user_exp)
    await level_up(user_names, message.author, message.channel)
    await client.process_commands(message)

1 Answers1

0

I was able to figure out what the issue was. Connections need to be reestablished when Databases are not in use. Inside the await commands you use the following:

mydb = mysql.connector.connect(
 host="localhost",
 user="yourusername",
 passwd="yourpassword")
 mycursor = mydb.cursor()
 mycursor.execute("YOUR SQL CODE")

You will need to do this every time a message is sent.