Error while trying to import Meraki __init__ raise APIKeyError()

Solved
VictorTJ
Here to help

Error while trying to import Meraki __init__ raise APIKeyError()

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
VictorTJ
Here to help

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
VictorTJ
Here to help

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()

PhilipDAth
Kind of a big deal
Kind of a big deal

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.

 

VictorTJ
Here to help

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

VictorTJ
Here to help

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)

 

Get notified when there are additional replies to this discussion.