MySQL Forums
Forum List  »  Connector/Python

Re: MySQL Python Connector - Cursor is not connected
Posted by: Shoumik Das
Date: November 10, 2020 11:01PM

Hi Pete,

This is the error that I get:

myCursor object: MySQLCursorBuffered: (Nothing executed yet)
Traceback (most recent call last):
File "testcursor.py", line 62, in <module>
fetch_count()
File "testcursor.py", line 45, in fetch_count
mycursor.execute(sql,val)
File "/usr/local/lib/python3.6/dist-packages/mysql/connector/cursor.py", line 519, in execute
raise errors.ProgrammingError("Cursor is not connected")
mysql.connector.errors.ProgrammingError: Cursor is not connected


The fetch_count() procedure is defined as follows:

def fetch_count():
try:
print("\nChecking db connectivity before query...")
connect_database()
sql="SELECT count(*) FROM status"
val=()
global mycursor
print("myCursor object:",mycursor)
mycursor.execute(sql,val)
myresult=mycursor.fetchone()
print("\nRecord count: ", myresult[0])
except mysql.connector.Error as q:
print("["+datetime.datetime.now().strftime("%a %b %d, %Y %I:%M:%S %p")+"] Database Error: "+str(q)+"\nProcedure: fetch_count()")

Options: ReplyQuote


Subject
Written By
Posted
Re: MySQL Python Connector - Cursor is not connected
November 10, 2020 11:01PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.