Forums

ERROR 2013: Lost connection to MySQL server during query

I want to start this one off by saying that I'm running this command from pythonista in a script.

I followed the guide here in attempts to create a task to import data from an api call to my db

https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/


in my #do stuff tag I have this where result is an int of ~1097

mycursor = connection.cursor()

sql = "UPDATE foldercount SET active = %s"
val = (result)
mycursor.execute(sql, val)

mydb.commit()

print(mycursor.rowcount, "record inserted.")

db.close()

I receive the error in the subject line and it's stopping at

mycursor.execute(sql, val)

There is no hang time and it happens almost immedietly.

I think your issue may be that val needs to be a tuple. So, where you assign to val, it should be:

val = (result,)