Python Forum

Full Version: ReferenceError: weakly-referenced object no longer exists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi there. I have been working on a library managment system. I am using MySQL as DB and Tkinter as GUI.

This error:

Error:
File "C:\Program Files\Python38\lib\site-packages\mysql\connector\cursor_cext.py", line 232, in executeif not self._cnx:ReferenceError: weakly-referenced object no longer exists
is being returned by this chunk of code:

def submit():
    search_words = search_entr.get()
    search_type = variable.get()
    if search_type == "Pick A Search Type":
        messagebox.showerror("Invalid Choice", "'Pick A Search Type' is not a valid search type.")
    else:
        global results
        if search_type == "ISBN":
            cur.execute("SELECT * FROM Books WHERE ISBN = %s", (search_words))
            results = cur.fetchball()
        if search_type == 'Title':
            cur.execute("SELECT * FROM Books where ITLE = %s", (search_words))
            results = cur.fetchball()
        if search_type == "Author":
            cur.execute("SELECT * FROM Books WHERE AUTHOR = %s", (search_words))
            results = cur.fetchball()
I have looked high and low for a solution, but have found none.

Please help

Thanks in advance
Please help
What is line 232? You should post the entire error message, including the traceback.
Line 232 is a line in C:\Program Files\Python38\lib\site-packages\mysql\connector\cursor_cext.py
from the MySQL library.

The full traceback is:
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "C:\Users\good\Desktop\LibraryManagmentSystem\search_book.py", line 58, in submit cur.execute("SELECT * FROM Books where ITLE = %s", (search_words)) File "C:\Program Files\Python38\lib\site-packages\mysql\connector\cursor_cext.py", line 232, in execute if not self._cnx: ReferenceError: weakly-referenced object no longer exists
In this line are you trying to pass a tuple?
cur.execute("SELECT * FROM Books WHERE ISBN = %s", (search_words))
If so, the syntax is
cur.execute("SELECT * FROM Books WHERE ISBN = %s", (search_words,))
The trailing comma tells Python this is a single element tuple, not something surrounded by parenthesis.
I tried that, it still returned the same error. I cant figure out what i am referring to weakly.
In my function, what is the weakly-referred-to object?
What is the problem with my code in relation to the RefferenceError
Most likely it is this:
search_words = search_entr.get()
I don't know what search_entr is so I cannot say for sure. You could do a query that doesn't use search_words to verify.
show minimal reproducible example. It looks like cur object` has been garbage collected when you try to use it, i.e. it was destroyed.
Pages: 1 2