I am working with tkinter and I need to bind a list to a combobox. I try to get the data from a Mysql database, but when I try to get it out, the console throws me:
TypeError: 'NoneType' object is not iterable
Y points to the list variable.
Here is the code, I copied it from a tutorial on the internet:
conn= conn=mysql.connector.connect(host="localhost",
user="root",
password="Baelca1", database="Lista_datos_Baelca")
cursor1=conn.cursor()
cursor1.execute('''CREATE TABLE IF NOT EXISTS Camiones (Tipo text, Peso BIGINT, capacidad BIGINT)''')
query="SELECT distinct(Tipo) as Tipo FROM Camiones"
datos=cursor1.execute(query)
lista =[r for r, in datos]
conn.commit()
conn.close()
The database is not empty, it has information. If someone can tell me what I'm doing wrong, please and thank you very much.
Using mysql.connector is wrong. The method
mysql.execute()
doesn't return anything, that 's why theNone
. When executing the query, the cursor must be used to extract the data:Or you can also use fetchone() to process row by row and thus generate the desired result in one go.