Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
<_io.BufferedRandom name =
#1
Does anyone have experience with this kind of error? The app purpose is on click 'Upload Image' to select image and upload to the db as blob. I'm getting strange error.
from tkinter import *
from tkinter import Tk
import sqlite3
from tkinter import filedialog
from tkinter import messagebox

root = Tk()
root.title('Interface Image Insert&Retrive')
root.geometry('600x600+200+200')

# Function Open IMG
def openImg():
    fileimg = filedialog.askopenfile(mode = 'rb+', initialdir = "/Desktop/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("png", "*.png")))
    my_label = Label(text = fileimg).grid(row = 2, column = 0)
    content = fileimg.read()
    if not fileimg:
        return
    else:
        try:
            con = sqlite3.connect('example.db')
            cur = con.cursor()
            query = cur.execute("INSERT INTO employees (employee_img) VALUES (?)")
            data_tup = (content)
            cur.execute(query, (data_tup,))
            cur.commit()
            cur.close()
        except sqlite3.Error as error:
            messagebox.showerror('Error', 'Faield to insert blob data into sqlite table')

lbl_upload = Label(root, text = 'Please Select your image')
lbl_upload.grid(row = 0, column = 0, padx = 0)
btn = Button(root, text = 'Upload Image', padx = 20, command = lambda : openImg())
btn.grid(row = 1, column = 0, padx = 0)




root.mainloop()
Reply
#2
Do you have a full traceback, not just the one line error from it?

The message suggests that somewhere is a function called "notes_counter", and that function is printed rather than called.

>>> def notes_counter():
...     pass
...
>>> print(notes_counter)
<function notes_counter at 0x10599cbf8>
But that function name doesn't appear in the code you've shown, and I don't see any references to that name in the tkinter or sqlite3 packages. Without a traceback there's nothing to tie the two together.
Reply
#3
I'm not getting any error in console. My concern is "content = fileimg.read()" statement is wrong.I'm new with python, but still I checked the manual for binary file(rb+), the db BLOB type.

[Image: img.png]
Reply
#4
I think you changed the post after I replied.

The error in the dialog says something in the try block failed. You could add information to the dialog (like the query and the data_tup) to make sure they are correct, or try looking for sqlite3.error information and reporting that.
Reply
#5
(Oct-18-2020, 03:04 AM)bowlofred Wrote: I think you changed the post after I replied.

The error in the dialog says something in the try block failed. You could add information to the dialog (like the query and the data_tup) to make sure they are correct, or try looking for sqlite3.error information and reporting that.

I refreshed my page by mistake and I put the old post subject, I appolagize for that. However, I found my error:

try:
data_tup = (content)
con = sqlite3.connect('example.db')
cur = con.cursor()
query = ("INSERT INTO employees (employee_img) VALUES (?)")
cur.execute(query, (data_tup,))
con.commit()
except sqlite3.Error as error:
print(error)
#messagebox.showerror('Error', 'Faield to insert blob data into sqlite table')
Reply


Forum Jump:

User Panel Messages

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