dashboard.switch.createNetworkSwitchAccessPolicy doesn't seem to be working properly from Python

shngrhm27
Here to help

dashboard.switch.createNetworkSwitchAccessPolicy doesn't seem to be working properly from Python

I'm trying to create a new access policy with a Python script using the Meraki library.

 

I'm 'getting' the model policy from a known good network switch, & trying to 'put' it on a few more network switches.

 

access_policy = dashboard.switch.getNetworkSwitchAccessPolicies(network_id)
ap_name = access_policy[0]["name"]
radiusServers = access_policy[0]["radiusServers"]
dict_radiusServers = radiusServers[0]
pop_radiusServers = dict_radiusServers.pop('serverId')
radiusServers = [dict_radiusServers]
radiusTestingEnabled = access_policy[0]["radiusTestingEnabled"]
radiusCoaSupportEnabled = access_policy[0]["radiusCoaSupportEnabled"]
radiusAccountingEnabled = access_policy[0]["radiusAccountingEnabled"]
hostMode = access_policy[0]["hostMode"]
urlRedirectWalledGardenEnabled = access_policy[0]["urlRedirectWalledGardenEnabled"]
radius = access_policy[0]["radius"]
guestPortBouncing = access_policy[0]["guestPortBouncing"]
radiusAccountingServers = access_policy[0]["radiusAccountingServers"]
dict_radiusAccountingServers = radiusAccountingServers[0]
pop_radiusAccountingServers = dict_radiusAccountingServers.pop('serverId')
radiusAccountingServers = [dict_radiusAccountingServers]
radiusGroupAttribute = access_policy[0]["radiusGroupAttribute"]
accessPolicyType = access_policy[0]["accessPolicyType"]
increaseAccessSpeed = access_policy[0]["increaseAccessSpeed"]
guestVlanId = access_policy[0]["guestVlanId"]
dot1x = access_policy[0]["dot1x"]
voiceVlanClients = access_policy[0]["voiceVlanClients"]
urlRedirectWalledGardenRanges = access_policy[0]["urlRedirectWalledGardenRanges"]

response = dashboard.switch.createNetworkSwitchAccessPolicy(network_id, ap_name, radiusServers, radiusTestingEnabled, radiusCoaSupportEnabled, radiusAccountingEnabled, hostMode, urlRedirectWalledGardenEnabled,
radius,
guestPortBouncing,
radiusAccountingServers,
radiusGroupAttribute,
accessPolicyType,
increaseAccessSpeed,
guestVlanId,
dot1x,
voiceVlanClients,
urlRedirectWalledGardenRanges)

Here's a printout of all those variables:

L_599541700393704277
LHC-NAC-802.1X-Wired
[{'organizationRadiusServerId': '3797660385780170753', 'host': '10.0.19.148', 'port': 1812}]
True
True
True
Multi-Domain
True
{'criticalAuth': {'dataVlanId': 100, 'voiceVlanId': 10, 'suspendPortBounce': False}, 'failedAuthVlanId': 100, 'reAuthenticationInterval': 86400}
True
[{'organizationRadiusServerId': '3797660385780170753', 'host': '10.0.19.148', 'port': 1813}]
11
Hybrid authentication
True
100
{'controlDirection': 'both'}
True
['10.0.0.0/8']

I'm getting an error message:

response = dashboard.switch.createNetworkSwitchAccessPolicy(network_id, ap_name, radiusServers, radiusTestingEnabled, radiusCoaSupportEnabled, radiusAccountingEnabled, hostMode, urlRedirectWalledGardenEnabled,
radius,
...<7 lines>...
voiceVlanClients,
urlRedirectWalledGardenRanges)
TypeError: Switch.createNetworkSwitchAccessPolicy() takes 9 positional arguments but 19 were given

I was able to create a policy using the Meraki Developer Hub Dashboard API, only after enabling the 'walledgarden' & adding a subnet.

Any ideas on what I'm doing wrong?

 

 

 



1 Reply 1
nan3540
Here to help

You have given all you arguments as positional arguments to the function

dashboard.switch.createNetworkSwitchAccessPolicy

but the function expects only some of the arguments as positional, the rest should be keyword arguments, like in the below function call

 

response = dashboard.switch.createNetworkSwitchAccessPolicy(
    network_id, name, radius_servers, radius_testing_enabled, radius_coa_support_enabled, radius_accounting_enabled, host_mode, url_redirect_walled_garden_enabled, 
    radius={'criticalAuth': {'dataVlanId': 100, 'voiceVlanId': 100, 'suspendPortBounce': True}, 'failedAuthVlanId': 100, 'reAuthenticationInterval': 120, 'cache': {'enabled': False, 'timeout': 24}}, 
    guestPortBouncing=False, 
    radiusAccountingServers=[{'organizationRadiusServerId': '42', 'host': '1.2.3.4', 'port': 22, 'secret': 'secret'}], 
    radiusGroupAttribute='11', 
    accessPolicyType='Hybrid authentication', 
    increaseAccessSpeed=False, 
    guestVlanId=100, 
    dot1x={'controlDirection': 'inbound'}, 
    voiceVlanClients=True, 
    urlRedirectWalledGardenRanges=['192.168.1.0/24']
)

 

you can read more about arguments to functions in below article

https://profound.academy/python-mid/positional-and-keyword-arguments-5LvKxDSUICCBH7Z96b1n 

Get notified when there are additional replies to this discussion.