我正在向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
答案 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)