Meraki rest API doesnt accept None as an argument Python (probably noob question)

Solved
Notworks
Conversationalist

Meraki rest API doesnt accept None as an argument Python (probably noob question)

Hello my Meraki friends,

 

This is probably a noob question. I am trying to programmatically edit a VLAN by using the rest API with Python, however I ran into some troubles.

 

While sending the following json using using requests.put: https://nxxx.meraki.com/api/v0/devices/XXXX-XXXX-XXXX/switchPorts/[portnumber]

 

  Name Value Type

 'accessPolicyNumber'NoneNoneType
 'allowedVlans''all'str
 'enabled'Truebool
 'isolationEnabled'Falsebool
 'linkNegotiation''Auto negotiate'str
 'macWhitelist'NoneNoneType
 'name'NoneNoneType
 'number'10int
 'poeEnabled'Truebool
 'portScheduleId'NoneNoneType
 'rstpEnabled'Truebool
 'stickyMacWhitelist'NoneNoneType
 'stickyMacWhitelistLimit'0int
 'stpGuard''disabled'str
 'tags'NoneNoneType
 'type''trunk'str
 'udld''Alert only'str
 'vlan'2int
 'voiceVlan'NoneNoneType
 __len__19int

 

I get the following response: 

 

'errors': ['Cannot set whitelist on a trunk port', 'Invalid MAC whitelist. To disable MAC whitelist, set accessPolicyNumber to null.']

 

If you take a look at the first entry of the table above, 'accessPolicyNumber' is indeed filled with a NoneType thing, which is the python equivalent to a null character (right?). Setting 'stickyMacWhitelistLimit' to None is also not an option, since it has to be an integer, while strangely enough if i use get, 'stickyMacWhitelistLimit' is filled with a null character. (which was my motivation to put 0 there in the first place, leading to this).

 

API command documentation I used is this.

 

Thanks for your time!

 

 

1 Accepted Solution
Nash
Kind of a big deal

None is null, yes.

 

That looks like you're trying to use Update Device Switch Port?

 

What happens when you leave the items with value None out? I ran into this with... I forget the call... a while ago. It may have been this one. The GET request returns None options that'll make it unhappy if you include them with a PUT.

View solution in original post

3 Replies 3
Nash
Kind of a big deal

None is null, yes.

 

That looks like you're trying to use Update Device Switch Port?

 

What happens when you leave the items with value None out? I ran into this with... I forget the call... a while ago. It may have been this one. The GET request returns None options that'll make it unhappy if you include them with a PUT.

Notworks
Conversationalist

When I leave them out it works!

 

From my understanding I'd had to send the entire thing. So what I tried to do is do a get request on the port, alter the JSON response to the VLAN I want, and send the edited response back. Seems I can send any amount of key value pairs I want.

 

Although, it also seems that sending a wholly filled JSON thing with all the values does make the system go places.

Nash
Kind of a big deal

Finally got a chance to dig in my scripts, and it was this call.

 

This is probably ugly as heck, but my apparent solution from October:

 

for port in switchportsList:
    switchNum = port['number']
    empties = []
    for key, value in port.items():
        if value == None:
            empties.append(key)
    for item in empties:
        try:
            port.pop(item)
        except:
            print(f"Couldn't pop {item}")
    putSwitchport(arg_apikey, arg_serial, port, switchNum, shard)

 

Get notified when there are additional replies to this discussion.