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

前端 未结 2 975
眼角桃花
眼角桃花 2021-01-22 07:53

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 nothin

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-22 08:16

    You're calling cursor.fetchall() twice. You shouldn't be doing that.

    Change:

    row = cursor.fetchall()
    results = len(cursor.fetchall())
    clientName, clientAddr, unLocker = row[1], row[2], row[3]
    

    To:

    rows = cursor.fetchall()
    results = len(rows) 
    if results > 0:
        row = rows[0]
        clientName, clientAddr, unLocker = row[1], row[2], row[3]
    

    And while it doesn't have anything to do with your current problem, you should be using a parameterized query:

    query = "SELECT * FROM sessionkeys WHERE clientName=?" 
    cursor.execute(query, (value1,))
    

提交回复
热议问题