I am using mysql-connector-python 8.0.33 and tring to fetch all records from database using following code .
def retrieve_records():
try:
cursor = conn.cursor(buffered= True)
cursor.execute(f"SELECT * FROM {scanner.table_name}")
records = cursor.fetchall()
tree.delete(*tree.get_children())
for record in records:
tree.insert("", "end", values=record)
while cursor.nextset():
pass # Consume any remaining unread result sets
cursor.close()
except mysql.connector.Error as err:
messagebox.showerror("Error", f"An error occurred while retrieving the records: {err}")
I am calling following function in a loop and there is an issue. Every time when I run the program and the loop is executed very first time I get Unread result found error every time. In short it goes to exception block in every first iteration.
Basically my program scan the qr code and store it to database and show the data in json decoded format on UI and here is one feature that if there is data in database already it should load it in list first. But not working it is giving error as mentioned above.
Traceback (most recent call last):
File "C:\Users\Credencys\Desktop\qr\app.py", line 196, in <module>
retrieve_records()
File "C:\Users\Credencys\Desktop\qr\app.py", line 99, in retrieve_records
cursor = conn.cursor()
^^^^^^^^^^^^^
File "C:\Users\Credencys\AppData\Local\Programs\Python\Python311\Lib\site-packages\mysql\connector\connection_cext.py", line 676, in cursor
self.handle_unread_result(prepared)
File "C:\Users\Credencys\AppData\Local\Programs\Python\Python311\Lib\site-packages\mysql\connector\connection_cext.py", line 932, in handle_unread_result
raise InternalError("Unread result found")
mysql.connector.errors.InternalError: Unread result found
After removing try catch getting following trace and Open-cv is for that i am using this function in a program where open-cv is used.

fetchallis by itself enough to turn off this error.nextsetis unnecessary; you only have one SELECT here.tryandexcept, where does it fail? Is it on theexecuteor theclose?buffered=Trueparameter. In any case, are you doing other database accesses before you run this one? And if your problem isn't related to OpenCV (which it isn't), then don't include the tag.