Python Forum
ReferenceError: weakly-referenced object no longer exists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ReferenceError: weakly-referenced object no longer exists
#1
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
Reply
#2
Please help
Reply
#3
What is line 232? You should post the entire error message, including the traceback.
Reply
#4
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
Reply
#5
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.
Reply
#6
I tried that, it still returned the same error. I cant figure out what i am referring to weakly.
Reply
#7
In my function, what is the weakly-referred-to object?
Reply
#8
What is the problem with my code in relation to the RefferenceError
Reply
#9
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.
Reply
#10
show minimal reproducible example. It looks like cur object` has been garbage collected when you try to use it, i.e. it was destroyed.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner: Code not work when longer list raiviscoding 2 765 May-19-2023, 11:19 AM
Last Post: deanhystad
  local varible referenced before assignment SC4R 6 1,465 Jan-10-2023, 10:58 PM
Last Post: snippsat
  a longer docstring Skaperen 8 1,595 Aug-25-2022, 11:21 PM
Last Post: Skaperen
  UnboundLocalError: local variable 'wmi' referenced before assignment ilknurg 2 1,859 Feb-10-2022, 07:36 PM
Last Post: deanhystad
  Referenced before assignment finndude 3 3,223 Mar-02-2021, 08:11 PM
Last Post: finndude
  IDLE editing window no longer works chris1 2 2,157 Feb-06-2021, 07:59 AM
Last Post: chris1
  Code no longer working yk303 14 9,951 Dec-21-2020, 10:58 PM
Last Post: bowlofred
  UnboundLocalError: local variable 'figure_perso' referenced before assignment mederic39 2 2,229 Jun-11-2020, 12:45 PM
Last Post: Yoriz
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 2,140 May-27-2020, 08:34 AM
Last Post: DeaD_EyE
  local variable 'marks' referenced before assignment Calli 3 2,277 May-25-2020, 03:15 PM
Last Post: Calli

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020