使用Cornice在金字塔中使用Colander反序列化顶级列表

时间:2014-03-10 20:09:11

标签: python pyramid colander cornice

给定Content-Type: application/json的POST请求和["foo", "bar"]正文如何使用Cornice在Pyramid中创建一个漏勺模式来反序列化。

这就是我想出来的:

class SimpleList(colander.SequenceSchema):
    items = colander.SchemaNode(colander.String())

它在带有vanilla Colander的CLI中运行良好。但是,当我在像这样的Cornice服务上使用它时:

@simple_list_service.post(schema=SimpleList)
def simple_list_post(request):
    print(request.validated)

我明白了:

{"errors": [{"name": "items", "description": "items is missing", "location": "body"}], "status": "error"}

有什么建议吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

当前版本的cornice仅允许colander.MappingSchema进行架构验证。其他任何事情都会引发异常(很明显,在你做得更远之前,你做了这个更改)。

因此,除非事情发生变化,否则您无法验证列表作为输入。

相关问题