cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4375
Views
1
Helpful
4
Replies

Error while trying to import Meraki __init__ raise APIKeyError()

Virgil Wilson
Level 2
Level 2

I'm trying to import Meraki and get error of __init__ raise APIKeyError()

Here is the script I'm using

MERAKI_DASHBOARD_API_KEY='093b24e85df15a3e66f1fc359f4c48493eaa1b73' # Demo API Key
import meraki
dashboard = meraki.DashboardAPI()
my_orgs = dashboard.organizations.getOrganizations()

Here is where it fails


# Check API key
api_key = api_key or os.environ.get(API_KEY_ENVIRONMENT_VARIABLE)
if not api_key:
raise APIKeyError()

Here is the output

C:\Users\MerakiAppData\Local\Programs\Python\Python38\Lib\site-packages\meraki\__init__.py", line 61, in __init__
raise APIKeyError()

meraki.exceptions.APIKeyError: Meraki API key needs to be defined

Any help would be apricated in advance.

1 Accepted Solution

Accepted Solutions

I figured out what the problem was. I wasn't passing the api_key into the argument.

dashboard = meraki.DashboardAPI()

should have been dashboard = meraki.DashboardAPI(api_key)

View solution in original post

4 Replies 4

Virgil Wilson
Level 2
Level 2

Correction to my post

I ran each line into the python console and it isn't failing in the import Meraki. It is failing when it calls dashboard = meraki.DashboardAPI()

Philip D'Ath
Meraki Community All-Star
Meraki Community All-Star

MERAKI_DASHBOARD_API_KEY='093b24e85df15a3e66f1fc359f4c48493eaa1b73' # Demo API Key

...

api_key = api_key or os.environ.get(API_KEY_ENVIRONMENT_VARIABLE)

You have defined a variable called MERAKI_DASHBOARD_API_KEY and then referenced api_key.

You could perhaps use:

api_key = MERAKI_DASHBOARD_API_KEY or os.environ.get(API_KEY_ENVIRONMENT_VARIABLE)

or:

api_key = 093b24e85df15a3e66f1fc359f4c48493eaa1b73'

instead of using MERAKI_DASHBOARD_API_KEY.

Thanks for the reply

However I get the same error

Code

pi_key='093b24e85df15a3e66f1fc359f4c48493eaa1b73' # Demo API Key
import meraki
dashboard = meraki.DashboardAPI()

File "C:\Users\Meraki\AppData\Local\Programs\Python\Python38\Lib\site-packages\meraki\__init__.py", line 61, in __init__
raise APIKeyError()

meraki.exceptions.APIKeyError: Meraki API key needs to be defined

I figured out what the problem was. I wasn't passing the api_key into the argument.

dashboard = meraki.DashboardAPI()

should have been dashboard = meraki.DashboardAPI(api_key)