Skip to content
Advertisement

python 3.6 socket pickle data was truncated

I can not send my numpy array in socket. I use pickle but my client pickle crashes with this error: pickle data was truncated

My server : I create a numpy array and I want to send in my client with pickle (it’s work)

JavaScript

My client He has my numpy array, but I can not load with pickle. I have this error.

JavaScript

Advertisement

Answer

the problem is that if the size of the pickled data is > 4096 you only get the first part of the pickled data (hence the pickle data was truncated message you’re getting)

You have to append the data and pickle it only when the reception is complete, for example like this:

JavaScript

increasing a bytes object is not very performant, would be better to store the parts in a list of objects, then join, though. Faster variant:

JavaScript
Advertisement