[Python] I get "Unread result found" after connecting to an old MySQL server when creating a...

Discussão em 'Python' iniciado por Stack, Novembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    FIX: adding consume_results=True to mysql.connector.connect fixed the problem. Fetching results is extremely slow, but it works!


    I have two MySQL servers, an ancient one version 5.7.17 and a newer 8.0.12. My python script executes without any problems after connecting to the newer database, but throws "Unread result found" exception when trying to perform any action on older server (It does connect).

    This problem is different from any other "Unread result found" issue I have seen, because setting buffered=True, buffered=False or anything else in cursor has no effect. Take a look at this example code:

    try:
    database = mysql.connector.connect(
    user="...",
    password="...",
    database="...",
    host="...",
    port=3306,
    autocommit=True
    )
    except mysql.connection.Error as err:
    print(err.msg)
    exit(1)

    try:
    print("A")
    cursor = database.cursor() # empty, buffered=True, buffered=False, anything, it doesn't change anything
    print("B")
    cursor.execute("SELECT * FROM some_table;")
    print("C")
    data = cursor.fetchall()
    except mysql.connector.Error as err:
    print("D")
    print(err.msg)


    In this case the script will crash on database.cursor() printing out A, D, and an error message in the console. All other issues I have read are pointing at fetchone or fetchall methods, however in my code those are not even executed.

    TLS versions on a problematic server TLSv1,TLSv1.1. TLS versions on a good server TLSv1,TLSv1.1,TLSv1.2.

    By MySQL servers i mean MySQL, not MariaDB.

    What I didn't do: moving from mysql.connector to other MySQL python library - this will require rewriting whole application and I don't have time to do that.


    Traceback as requested:

    Traceback (most recent call last):
    File "/mnt/c/Users/{removed}/Desktop/{removed}/{removed}/./dumpToFile", line 155, in <module>
    row_count = cm.{removed function name}(attribute, single_day, mdb, sdb)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/mnt/c/Users/{removed}/Desktop/{removed}/{removed}/conv_methods.py", line 298, in {removed function name}
    mysql_cursor = mdb.cursor(buffered=True)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 868, in cursor
    self.handle_unread_result()
    File "/usr/lib/python3/dist-packages/mysql/connector/connection.py", line 1132, in handle_unread_result
    raise errors.InternalError("Unread result found")
    mysql.connector.errors.InternalError: Unread result found

    Continue reading...

Compartilhe esta Página