Meraki Python SDK

Solved
bayet
Getting noticed

Meraki Python SDK

Hello,

 

I'm trying ti use Python SDK for Meraki configuration, but untill now without success. My Python configuration is done as the instruction in this link " https://github.com/meraki/meraki-python-sdk#admins_controller ". My IDE is Visual Code Studio.

 

I also successfull tested the installation after the installation as:

 

E:\Python\Python37\meraki-python-sdk-master>nosetests

----------------------------------------------------------------------
Ran 0 tests in 0.141s

OK

 

All four folders have python file, but can some explain to me where to start, which python file in which folder should I use. ( see screenshot)

I'm not a programmer, but I want to learn how to use those python API files. I also went  through lots of Meraki document without success.

 

Thank you.VsCode.PNG

 

1 Accepted Solution
RubenG
Getting noticed

You have to import the meraki.py file and from there import "Meraki"

 

so if your Project File is not in same folder like the example in the image below then you would have to point to folder to file and then Meraki Ass follows:

 

from meraki.meraki import Meraki

tempsnip.png Notice how my test.py script is not in the same folder as meraky.py. If it is in the same folder then use:

from meraki import Meraki

 Try running just the import, when you run it you shouldn't get any errors, then it means it succeeded. You can then start playing with the functions in the SDK kit.

View solution in original post

4 Replies 4
RubenG
Getting noticed

You have to import the meraki.py file and from there import "Meraki"

 

so if your Project File is not in same folder like the example in the image below then you would have to point to folder to file and then Meraki Ass follows:

 

from meraki.meraki import Meraki

tempsnip.png Notice how my test.py script is not in the same folder as meraky.py. If it is in the same folder then use:

from meraki import Meraki

 Try running just the import, when you run it you shouldn't get any errors, then it means it succeeded. You can then start playing with the functions in the SDK kit.

bayet
Getting noticed

Thank you RubenG.

 

Test script and meraki.py are in de same folder, but still get the error message shown below.

 

MerakiSDK.PNG

bayet
Getting noticed

SDK test.py now running whitout error after putting the testsdk.py on the same level as teh meraki folder.

 

MerakiSDK01.PNG

RubenG
Getting noticed

Ok, the issue is that you can't have your script in the same folder as meraki.py.

 

I took a look at the code and the reason it failed the first time when you put it in the same folder as meraki.py is that the code assumes the remainder of the modules are under the meraki folder. 

Screen Shot 2019-05-13 at 1.23.31 PM.png

By running your script on the same folder as meraki.py file then that means you are in the meraki folder and therefore the path of the script starts there. So you would have to change the path in order for it to work, because it references the folder it is in. Or you can just run it outside the folder. (I would recommend this so you don't have to change anything in the modules). That is why it failed and you get the error "No module named 'meraki.decorators'".

 

Apologies, oversight on my part.

 

Another thing I noticed when it did work for you, you are importing the file "meraki.py". What you really want to import is the Class object "Meraki" it is case sensitive. 

 

So you have to import it as:

from meraki.meraki import Meraki

the first meraki tells the folder, the second tells the File name, the import functions states that it wants to import something from the file. And the "Meraki" states what you want to import.

 

Try running this in your testsdk.py:

from meraki import meraki
x_cisco_meraki_api_key = 'x_cisco_meraki_api_key' ##CHANGE this to your Meraki API key client = Meraki(x_cisco_meraki_api_key) organization_id = 'organizationId' ##CHANGE this to an OrganizationID you are using to test admins_controller = client.admins result = admins_controller.get_organization_admins(organization_id) print (result) ##You will see the admins of the Organization printed in a Dictionary format.

It will fail because the import is not correct. In order to utilize it in your "testsdk.py" script you will have to change the following line

client = Meraki(x_cisco_meraki_api_key)

to 

 

client = meraki.Meraki(x_cisco_meraki_api_key)

since you need to call the Class Object in that file in order to create this variable. And anytime you utilize it you will have to call it with "meraki." leading that call. As shown above. 

 

it is easier if you just use the following to import:

from meraki.meraki import Meraki

so you don't have to call "meraki.Meraki" every time you call the Meraki object. It is a matter of preference. 

 

Try the following with the corrected import:

from meraki.meraki import Meraki

x_cisco_meraki_api_key = 'x_cisco_meraki_api_key' ##CHANGE this to your Meraki API key
client = Meraki(x_cisco_meraki_api_key)
organization_id = 'organizationId' ##CHANGE this to an OrganizationID you are using to test
admins_controller = client.admins
result = admins_controller.get_organization_admins(organization_id)
print (result)
##You will see the admins of the Organization in a Dictionary format.

You will see the admins of the organization.

 

It'll be easier getting the "organizationId" from postman.

 

Let me know if you have any other questions, sorry for the error earlier. I didnt realize the imports assumed it was being called from a different folder.

Get notified when there are additional replies to this discussion.