Python Forum
how to send an image from server to client using PICKLE module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to send an image from server to client using PICKLE module
#1
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:

Error:
feed = pickle.loads(d) raise ValueError, "insecure string pickle" ValueError: insecure string pickle
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!
Reply
#2
suggestion page -

https://stackoverflow.com/questions/1746...ing-pickle
Regards
-------- *
“Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.”
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Paramiko Server -- Exception (server): Error reading SSH protocol banner ujlain 3 4,280 Jul-24-2023, 06:52 AM
Last Post: Gribouillis
  Client/Server proper finalizing transfer wolfman5874 1 1,423 Jul-04-2022, 07:35 PM
Last Post: wolfman5874
Bug Problem connecting TLS client written in C++ and Twisted server gpropf 0 1,361 Jun-12-2022, 05:57 PM
Last Post: gpropf
  Server/client basic communication ebolisa 0 2,009 Sep-30-2021, 12:22 PM
Last Post: ebolisa
  Help with Websocket-Client Module - Infinite Loop CluelessChris 0 3,887 Apr-25-2021, 01:53 PM
Last Post: CluelessChris
  Client server Multithreading Anan 6 5,755 Apr-21-2021, 08:19 PM
Last Post: SheeppOSU
Question Trouble with Client/Server reverse Shell! Gilush 0 2,757 Feb-03-2021, 01:04 PM
Last Post: Gilush
  Basic client server code question swisscheese 4 3,192 Dec-12-2020, 08:51 AM
Last Post: Larz60+
  How can i create a server for already existing client using Python? Chapanson 21 7,320 Aug-19-2020, 09:12 AM
Last Post: DeaD_EyE
  Simple TCP Client and TCP Server Problem Vapulabis 5 4,336 Jul-12-2020, 05:09 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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