Search code examples
python-3.xmsgpackfalcon

msgpack.unpackb in Falcon


I try to learn and deploy sampel code for falcon tutorial in readthedocs. in this section when testing app by pytest tests get 1 failed with this title:

E msgpack.exceptions.ExtraData: unpack(b) received extra data.

how to solve this problem?

pytest output:

tests/test_app.py F                                                      [100%]

=================================== FAILURES ===================================
_______________________________ test_list_images _______________________________

client = <falcon.testing.client.TestClient object at 0x7f2cceed5490>

    def test_list_images(client):
        doc = {
            'images': [
                {
                    'href': '/images/1eaf6ef1-7f2d-4ecc-a8d5-6e8adba7cc0e.png'
                }
            ]
        }

        response = client.simulate_get('/images')
>       result_doc = msgpack.unpackb(response.content, raw=False)

tests/test_app.py:26: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   msgpack.exceptions.ExtraData: unpack(b) received extra data.

msgpack/_unpacker.pyx:209: ExtraData
============================== 1 failed in 0.15s ===============================

app.py, images.py and test_app.py are exactly the code in the tutorial without any changes.


Solution

  • In the previous step they changed the response type to MessagePack. If you kept JSON as a response type, this may be your problem.

    To solve replace

    result_doc = msgpack.unpackb(response.content, raw=False)
    

    by

    result_doc = json.loads(response.content)