how to send an image from server to client using PICKLE module - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: how to send an image from server to client using PICKLE module (/thread-26821.html) |
how to send an image from server to client using PICKLE module - dafdaf - May-14-2020 I have this sqlite3 database table in the server side that contains a BLOB object: q_conn = sqlite3.connect('questions_stack.db') q_c = q_conn.cursor() q_c.execute("""CREATE TABLE IF NOT EXISTS questions ( id INTEGER PRIMARY KEY, topic TEXT, username TEXT, likes INTEGER, pic BLOB) """)[/align] The client sends an image file in pieces by opening it 'rb': [align=justify]f = open(pic_path, "rb") l = f.read(1024) while l: client_socket.send(l) l = f.read(1024) client_socket.send("stop")[/align] and the server saves the image as post_pic file, and inserts the image object by opening it as 'wb' to the database column pic BLOB: [align=justify]f = open('post_pic'+".jpg", 'wb') # open in binary l = client.recv(1024) while l != "stop" and l != "nopic": f.write(l) l = client.recv(1024) f.close()I tried sending the table questions data to the client (so he could create a GUI) using pickle module: Server-side: q_conn = sqlite3.connect('questions_stack.db') q_conn.text_factory = str q_c = q_conn.cursor() q_c.execute("SELECT * FROM questions") feed = q_c.fetchall() data = pickle.dumps(feed) q_conn.close() client.send(data)Client side: d = client_socket.recv(BUFSIZ) feed = pickle.loads(d)However, I got this error on the client-side: Do you have any idea what the problem is? and how can I fix it? I'd really appreciate it if you could help me!
RE: how to send an image from server to client using PICKLE module - nuffink - Jun-02-2020 suggestion page - https://stackoverflow.com/questions/1746825/valueerror-insecure-string-pickle |