I am executing a query against Mysql from a python script. I am using the anaconda distribution of python with the Oracle Mysql module. If I limit the query to ~500 rows it executes successfully. Anything above that results in an "Unread result found" exception. I can't understand what I am doing wrong. Any help is appreciated. The code is as follows:
import mysql.connector
import csv
cnx = mysql.connector.connect(user='user', password='password',
host='server',
port='3306',
database='db',
connect_timeout=2000,
buffered=True)
try:
query = "...large query that returns > 500 records..."
cursor = cnx.cursor()
cursor.execute(query)
print 'this will print'
results = cursor.fetchall()
print 'this will not print'
with open("data.csv", "wb") as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerows(results)
finally:
cursor.close()
cnx.close()