Error - builtins.TypeError: Object of type set is not JSON serializable

Solved
VictorTJ
Here to help

Error - builtins.TypeError: Object of type set is not JSON serializable

I'm getting an error when running this code.  while trying to update the network syslog server values.  It fails when it tries to run the update = dashboard.networks.updateNetworkSyslogServers(network_id, servers) line. below is the script I'm tying to run. 

 

thanks for your help in advance

 

# File will update a syslog server in networks based on county tag


import meraki

# Set Meraki variables
api_key = '6bec40cf957de430a6f1f2baa056b99a4fac9ea0' # Public Sandbox

syslog_server = '10.178.207.68' # Ashburn Syslog server

# sets what networks to update by the country tag
country_tag = 'Country-Lab-US'

# Sets the syslog server values
servers = [{'host': {syslog_server}, 'port': 513, 'roles': ['Flows', 'Security events']}]

network_loop = 0

dashboard = meraki.DashboardAPI(api_key)

all_networks = dashboard.organizations.getOrganizationNetworks(organization_id)

while network_loop < len(all_networks):
if country_tag in all_networks[network_loop]["tags"]:
network_id = all_networks[network_loop]['id']
response = dashboard.networks.updateNetworkSyslogServers(network_id, servers)
print(f' The network ID is {network_id} and country tag is {all_networks[network_loop]["tags"]}')
network_loop +=1
else:
print('nothing was updated')
network_loop +=1

 

 

1 Accepted Solution
VictorTJ
Here to help

I figured out what it was.  I was trying to set the security event on networks that didn't have an MX in it.

View solution in original post

4 Replies 4
PhilipDAth
Kind of a big deal
Kind of a big deal

Try:

 

servers = [{'host': syslog_server, 'port': 513, 'roles': ['Flows', 'Security events']}]

Thanks for that.  Now I'm getting

 

meraki.exceptions.APIError: networks, updateNetworkSyslogServers - 400 Bad Request, {'errors': ['Please select at least one valid role for 10.178.207.68 513']}

PhilipDAth
Kind of a big deal
Kind of a big deal

Setup the Dashboard just how you want it.  Then use the API to request the config and look at the parameters returned, and then put them into your code.

VictorTJ
Here to help

I figured out what it was.  I was trying to set the security event on networks that didn't have an MX in it.

Get notified when there are additional replies to this discussion.