python eve补丁请求中的生产中的模式验证错误

时间:2015-04-13 07:52:08

标签: python eve

我正在向python eve发送补丁请求。 但它产生以下错误

 "An exception occurred: __init__() got an
 unexpected keyword argument   'allow_unknown'"

我的架构结构如下所示。

    'notifications': {
        'type': 'list',
        'schema': {
            'type':'dict',
            'items':{
                'friendid': {
                    'type': 'objectid',
                    'data_relation': {
                        'resource': 'people',
                        'embeddable': True
                    }
                },

                'seen':{
                    'type':'boolean',
                    'default':False
                },
                'timestamp':{
                    'type': 'integer',
                },
                'daterequest':{
                    'type':'string'
                }
            }
        }
    },

我对架构的修补参数如下所示。

 notifications: [{
                   friendid: "552b71db60efab0ce3d4aa1b",
                   seen: false, 
                   timestamp: 120, 
                   daterequest: "hai"
                }]

我的完整架构文件显示在下面的链接中。 settings file

2 个答案:

答案 0 :(得分:0)

不确定您获得的实际错误(看起来它与通知架构完全无关:您的文件中甚至没有allow_unknown规则。)

但是,我测试了您的设置,结果发现notifications正在使用过时的items规则,这反过来会导致POST和PATCH方法的验证错误。尝试使用以下编辑更新您的信息:

    'notifications': {
        'type': 'list',
        'schema': {
            'type':'dict',
            # replace 'items' with 'schema':
            'schema':{
                'friendid': {
                    'type': 'objectid',
                    'data_relation': {
                        'resource': 'people',
                        'embeddable': True
                    }
                },

                'seen':{
                    'type':'boolean',
                    'default':False
                },
                'timestamp':{
                    'type': 'integer',
                },
                'daterequest':{
                    'type':'string'
                }
            }
        }
    },

之后我可以毫无问题地发布 PATCH。希望这会有所帮助。

答案 1 :(得分:0)

如果您使用自定义验证程序类,则会出现此错误,该类会覆盖__init__但不接受allow_unknown作为关键字参数,例如像这样:

from eve import Eve

class MyValidator(eve.io.mongo.Validator):

    # not accepting keyword arguments here will cause the error
    def __init__(self, **kwargs):
        ...

app = Eve(__name__, validator=MyValidator)