I a unsure why my connection is giving me an error while I loop through my table to search for elements of my list:
try:
conn = mysql.connector.connect(user='root', password='####',host='####',database='###', allow_local_infile=True)
cursor = conn.cursor()
except Exception:
traceback.print_exc()
print("I am unable to connect to the database")
index= 0
for i in range(0, len(listdates)):
date= listdates[i]
print(date)
try:
query = ("SELECT * FROM search WHERE time= %s;", (date,))
cursor.execute(query)
row= cursor.fetchall()
if not row:
index = i
break
except Exception:
traceback.print_exc()
print("did not return row")
I am not sure what the issue is. My connection is fine since when I execute the query outside the loop I have no issue. In the larger code this will go in, I have no issue looping through my queries. I don't know what is wrong.
error: mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at '127.0.0.1:3306', system error: Connection not available.
I attempted to use cursor.close() in the loop. I also have tried using " with conn.cursor() as cursor:" outside of of the loop.