MySQLdb raises "execute() first" error even though I execute before calling fetchall
You're calling cursor
multiple times, which creates multiple cursors. You execute the query on the first cursor, then fetch from the second. Since you didn't execute anything on the second, you get this error. Use only one cursor.
cursor = g.db.cursor()cursor.execute(...)rows = cursor.fetchall()