Python, mysql.connector Error: No Result Set to Fetch From; cgitb shows correct value being passed to function

Viewed 22304

Allright this one's got me baffled so I decided to see if I could find a response on here, I've searched up and down and several stackoverflow questions and answers and nothing has seemed to work. All I'm trying to do is a SELECT * FROM statement using mysql.connector and I keep getting a "No Result Set" error. Here's the code:

def session_fetch(value1):
    cnx = mysql.connector.connect(user='xxx', password='xxx', 
    host='127.0.0.1', database='xxx') 
    cursor = cnx.cursor()
    query = ("SELECT * FROM sessionkeys "
             "WHERE clientName='%s';") % value1 
    cursor.execute(query)
    row = cursor.fetchall()
    results = len(cursor.fetchall())
    clientName, clientAddr, unLocker = row[1], row[2], row[3]
    cnx.commit()
    cursor.close()
    cnx.close()

The error from cgitb shows: C:\inetpub\wwwroot\flighttoolsbz\validator.py in session_fetch(value1='ericdsmith86')
162 cursor.execute(query)
163 row = cursor.fetchall()
=> 164 results = len(cursor.fetchall())
165 clientName, clientAddr, unLocker = row[1], row[2], row[3]
166 cnx.commit()

InterfaceError: No result set to fetch from.
args = (-1, 'No result set to fetch from.', None)
errno = -1
msg = 'No result set to fetch from.'
sqlstate = None
with_traceback = built-in method with_traceback of InterfaceError object

But when I go through the MySQL workbench and run the same query using the same input value, it returns the one row i'm looking for, so it's definitely there. The only thing I can think of is that the %s formatter isn't taking what's being passed to the function as 'value1'. What am I missing?

2 Answers
Related