Python Forum
ReferenceError: weakly-referenced object no longer exists - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: ReferenceError: weakly-referenced object no longer exists (/thread-31471.html)

Pages: 1 2


ReferenceError: weakly-referenced object no longer exists - MrBitPythoner - Dec-13-2020

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


RE: ReferenceError: weakly-referenced object no longer exists - MrBitPythoner - Dec-13-2020

Please help


RE: ReferenceError: weakly-referenced object no longer exists - deanhystad - Dec-13-2020

What is line 232? You should post the entire error message, including the traceback.


RE: ReferenceError: weakly-referenced object no longer exists - MrBitPythoner - Dec-13-2020

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



RE: ReferenceError: weakly-referenced object no longer exists - deanhystad - Dec-13-2020

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.


RE: ReferenceError: weakly-referenced object no longer exists - MrBitPythoner - Dec-13-2020

I tried that, it still returned the same error. I cant figure out what i am referring to weakly.


RE: ReferenceError: weakly-referenced object no longer exists - MrBitPythoner - Dec-14-2020

In my function, what is the weakly-referred-to object?


RE: ReferenceError: weakly-referenced object no longer exists - MrBitPythoner - Dec-14-2020

What is the problem with my code in relation to the RefferenceError


RE: ReferenceError: weakly-referenced object no longer exists - deanhystad - Dec-14-2020

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.


RE: ReferenceError: weakly-referenced object no longer exists - buran - Dec-14-2020

show minimal reproducible example. It looks like cur object` has been garbage collected when you try to use it, i.e. it was destroyed.