msgpack.unpackb 在猎鹰
msgpack.unpackb in Falcon
我尝试在 readthedocs 中学习和部署 falcon 教程的示例代码。
在 this section 中,当 pytest tests
测试应用程序时,get 1 失败,标题为:
E msgpack.exceptions.ExtraData: unpack(b) received extra data.
如何解决这个问题?
pytest 输出:
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和test_app.py就是教程中的代码,没有任何改动。
在上一步中,他们将响应类型更改为 MessagePack。如果您将 JSON 保留为响应类型,这可能是您的问题。
解决替换
result_doc = msgpack.unpackb(response.content, raw=False)
来自
result_doc = json.loads(response.content)
我尝试在 readthedocs 中学习和部署 falcon 教程的示例代码。
在 this section 中,当 pytest tests
测试应用程序时,get 1 失败,标题为:
E msgpack.exceptions.ExtraData: unpack(b) received extra data.
如何解决这个问题?
pytest 输出:
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和test_app.py就是教程中的代码,没有任何改动。
在上一步中,他们将响应类型更改为 MessagePack。如果您将 JSON 保留为响应类型,这可能是您的问题。
解决替换
result_doc = msgpack.unpackb(response.content, raw=False)
来自
result_doc = json.loads(response.content)