问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/42907315/unpacking-msgpack-from-respond-in-python