我正在探索为我的应用程序构建API,作为开发人员工具的一部分,我可以看到如下所示的有效负载-
-X POST -H "Content-Type:application/json" -d '{ "action": "DeviceManagementRouter", "method": "addMaintWindow", "data": [{"uid": "/zport/dmd/Devices/Server/Microsoft/Windows/10.10.10.10", "durationDays":"1", "durationHours":"00", "durationMinutes":"00", "enabled":"True", "name":"Test", "repeat":"Never", "startDate":"08/15/2018", "startHours":"09", "startMinutes":"50", "startProductionState":"300" } ], "type": "rpc", "tid": 1}
我看到以下错误-
{"uuid": "a74b6e27-c9af-402a-acd0-bd9c4254736e", "action": "DeviceManagementRouter", "result": {"msg": "TypeError: addMaintWindow() got an unexpected keyword argument 'startDate'", "type": "exception", "success": false}, "tid": 1, "type": "rpc", "method": "addMaintWindow"}
以下网址中的代码:
https://zenossapiclient.readthedocs.io/en/latest/_modules/zenossapi/routers/devicemanagement.html
答案 0 :(得分:0)
假设这是您真正的python代码,那么如果您想在python中传递多个参数,则应使用npm ERR! Linux 4.15.0-30-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! vx-leave-system@0.0.1 start: `node ./tools/server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vx-leave-system@0.0.1 start script 'node ./tools/server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the vx-leave-system package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./tools/server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs vx-leave-system
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls vx-leave-system
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/seelan/Documents/vx-leave-system/npm-debug.log
或*args
(关键字参数)。对您来说,**kwargs
似乎更合适。
kwargs
Here是有关如何使用它的好答案。还有更多general个在这里。
如果您不熟悉通则,请先阅读通则。
这应该使您在此阶段通过错误,但是您需要对def addMaintWindow(self, **kwargs):
"""
adds a new Maintenance Window
"""
_name = kwargs["name"]
# _name = kwargs.pop("name", default_value) to be fail-safe and
# it's more defensive because you popped off the argument
# so it won't be misused if you pass **kwargs to next function.
facade = self._getFacade()
facade.addMaintWindow(**kwargs)
return DirectResponse.succeed(msg="Maintenance Window %s added successfully." % (_name))
执行相同的操作;如果它不属于您,请确保您传递正确数量的命名参数。