I am wanting to create a function to export data from one of my MySQL tables to excel (csv) by clicking a button. The connection to the bank works normally, as does the graphical interface, but when I click the button, it results in the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\TESTES\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/TESTES/PycharmProjects/Heiken/A_FUNCTIONS_CADASTRO/Excel.py", line 25, in exp_rel_con_pag
cursor.execute(statm)
File "C:\Users\TESTES\PycharmProjects\Heiken\venv\lib\site-packages\pymysql\cursors.py", line 170, in execute
result = self._query(query)
File "C:\Users\TESTES\PycharmProjects\Heiken\venv\lib\site-packages\pymysql\cursors.py", line 328, in _query
conn.query(q)
File "C:\Users\TESTES\PycharmProjects\Heiken\venv\lib\site-packages\pymysql\connections.py", line 516, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "C:\Users\TESTES\PycharmProjects\Heiken\venv\lib\site-packages\pymysql\connections.py", line 750, in _execute_command
raise err.InterfaceError("(0, '')")
pymysql.err.InterfaceError: (0, '')
Below is the code:
import pymysql
from tkinter import *
excel = Tk()
excel.geometry("")
excel.title("excel teste")
conn = pymysql.connect(host="localhost", port=3306, user="root", password="", database="omnia")
print("connect successfull!")
cursor = conn.cursor()
cursor.execute("SELECT VERSION()")
versao = cursor.fetchone()
print("Versão do gerenciador Maria DB: %s" % versao)
conn.close()
def exp_rel_con_pag():
conn = pymysql.connect(host="localhost", port=3306, user="root", password="", database="omnia")
statm = "SELECT * FROM omniacademp INTO OUTFILE '/TMP/OMNIACADEMP.CSV' FIELDS TERMINATED BY ',' ENCLOSED BY "" LINES TERMINATED BY '\n'"
cursor.execute(statm)
bt = Button(excel, width=15, text="run", command=exp_rel_con_pag)
bt.place(x=10, y=10)
excel.mainloop()