-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
hashis a property of an object, you can try using the__setstate__and__getstate__pickle to convert to bytes when serialize the object.– Leonardo Santos