Python dictionary to list

SOLVED
Fabian1
Getting noticed

Python dictionary to list

Hi everyone,

 

this is more basic python, but I stuck with this problem:

 

When I get the data of an ssid, the response is always a dictionary ('name' : 'something, ' number' : 22...) from Meraki which is fine.

But if I want to update the ssid, it has to be done in a form of name = 'something, number = '22'...

How do you convert this? 

I don't want to hard code the config, I just want to change one of the values.

 

Thanks and best

Fabian

1 ACCEPTED SOLUTION

Accepted Solutions
Steinbep
Getting noticed

Re: Python dictionary to list

@PhilipDAthIs correct and this is probably the easiest way to do it.

 

A simple for loop through networks and ssids will get you through the data you need to change. Something like the below.

 

nets = meraki.organizations.getOrganizationNetworks(organizationId)

for net in nets:

    ssids = meraki.wireless.getNetworkWirelessSsids(net['id'])

    for ssid in ssids:

        if ssid['name'] == "something":

            ssid.update({'psk' : 'newpassword'}) # use the update() function when working with dictionaries. #

            ssidChange = meraki.wireless.updateNetworkWirelessSsid(net['id'], **ssid) # the double * (**) will unpack the dictionary and allow you to post the full dictionary as the new variables. Be careful with this as you may get a return value that won't post.  

 

View solution in original post

3 REPLIES 3
PhilipDAth
Kind of a big deal

Re: Python dictionary to list

Iterate through the dictionary and test each row for the value you are looking for (such as SSID) and then change that one row.

Steinbep
Getting noticed

Re: Python dictionary to list

@PhilipDAthIs correct and this is probably the easiest way to do it.

 

A simple for loop through networks and ssids will get you through the data you need to change. Something like the below.

 

nets = meraki.organizations.getOrganizationNetworks(organizationId)

for net in nets:

    ssids = meraki.wireless.getNetworkWirelessSsids(net['id'])

    for ssid in ssids:

        if ssid['name'] == "something":

            ssid.update({'psk' : 'newpassword'}) # use the update() function when working with dictionaries. #

            ssidChange = meraki.wireless.updateNetworkWirelessSsid(net['id'], **ssid) # the double * (**) will unpack the dictionary and allow you to post the full dictionary as the new variables. Be careful with this as you may get a return value that won't post.  

 

View solution in original post

Fabian1
Getting noticed

Re: Python dictionary to list

The **ssid and ssid.update did the trick, this is awsome, thank you guys 🙂

Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.