-2
How is it possible to serialize an object of the type _hashlib.HASH
, so that it is suitable for sending via sockets (sendall()
and send()
) ?
With the pickle is made:
hashed_Message = hashlib.sha256(message.encode('utf-8'))
serializedHashed_Message = pickle.dumps(hashed_Message)
conn.sendall(serializedHashed_Message)
But in doing so happens the following Exception:
Typeerror: can’t pickle _hashlib.HASH Objects
And when trying to send the object directly the sending function requires bytes. How to handle?
Thankful, it was one of the ways I was thinking of doing it, but wanted it the other way, because there are other objects that are not so simply serialized.
– FourZeroFive
If that
hash
is a property of an object, you can try using the__setstate__
and__getstate__
pickle to convert to bytes when serialize the object.– Leonardo Santos