3

I get the following error while trying msgpack.unpack:

ExtraData: unpack(b) received extra data.

Part of my code:

r1=requests.get('http://localhost:3000/fs?path='+r.json()['object'])
unp = msgpack.unpackb(r1.content)

Can someone help with that?

ballade4op52
  • 2,142
  • 5
  • 27
  • 42
Kamil Kurzyca
  • 31
  • 1
  • 3

1 Answers1

2

The doc's aren't very clear about this, but msgpack.unpackb is a "one-shot" unpacker - you can't give it a larger stream with extra data in it. I assume that you are getting multiple msgpack objects and you can read them with msgpack.Unpacker as in

r1=requests.get('http://localhost:3000/fs?path='+r.json()['object'])
for unp in msgpack.unpackb(r1.content):
    do something...

The reason for this is that the msgpack deserializer reads data in chunks for greater efficiency. For unpackb, where you can only return one object, its chunk reader consumed more of the data stream than it should have and you lost data.

tdelaney
  • 73,364
  • 6
  • 83
  • 116