1

I am exploring building an API to my application, as part of developer tool i can see the payload as below -

-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}

I see below error -

{"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"}

Code in below URL:

https://zenossapiclient.readthedocs.io/en/latest/_modules/zenossapi/routers/devicemanagement.html
goe
  • 337
  • 2
  • 14

1 Answers1

0

Assuming this is your real python code, then if you want to pass multiple params in python, you should use either *args or **kwargs (keyworded arguments). For you, it seems kwargs is more appropriate.

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))

Here is a good answer about how to use it. A more general one is here.

Read the general one first if you are not familiar with them.

This should get you pass the error at this stage but you will need to do the same for your facade.addMaintWindow; if it not owned by you, make sure you pass in a correct number of named arguments.

stucash
  • 1,078
  • 1
  • 12
  • 23