meraki / dashboard-api-python

Official Dashboard API library (SDK) for Python
MIT License
293 stars 154 forks source link

API Key Environment Variable doesn't behave as expected in Python #150

Closed kmanwar89 closed 3 years ago

kmanwar89 commented 3 years ago

This is my first time interacting with this particular library, and I'm still learning about API's, so please pardon my ignorance.

If I use Postman, I'm able to interact with the Dashboard API without issues. When using Python, the environment variables don't work as expected.

Development Environment

Expected behavior

Screenshot from 2021-03-11 12-54-21

Actual behavior

Steps to fix Use one of several methods to manage the API token

Requested response from developers

TKIPisalegacycipher commented 3 years ago

I'm not able to reproduce this on Ubuntu or Windows. Do you have any other steps to reproduce?

On Thu, Mar 11, 2021 at 10:04 AM Kadar Anwar @.***> wrote:

This is my first time interacting with this particular library, and I'm still learning about API's, so please pardon my ignorance.

If I use Postman, I'm able to interact with the Dashboard API without issues. When using Python, the environment variables don't work as expected.

Development Environment

  • Dell Inspiron Laptop
  • Ubuntu 20.04 - fresh install
  • Python 3.8
  • VSCode
  • Postman
  • bash for shell, using the default terminal with Ubuntu

Expected behavior

  • Exporting an environment variable within the terminal, and validating it from the output of the env command, should result in the variable being passed through to the instantiated object via the os.environs.get() method, which is present in init.py as witnessed here:

[image: Screenshot from 2021-03-11 12-54-21] https://user-images.githubusercontent.com/11323060/110832108-f09d9180-8268-11eb-99e9-3ea23febf11c.png

Actual behavior

  • Environment variable is not passed into the object, resulting in a 401 'Invalid API Key' error

Steps to fix Use one of several methods to manage the API token

  • Export the variable in the shell's .bashrc file and use os.environ.get() this shouldn't be required as the code is already present in the init, so this is duplicate effort
  • Leverage the python-dotenv library. This involves creating a .env file in the same directory as the code, adding it to .gitignore and adjusting file permissions accordingly to secure access to only the user. secure, but inconvenient
  • Manually defining the API token into the code as plaintext lease secure, most convenient
  • Write a separate bash script to handle managing the API token

Requested response from developers

  • Can the documentation be updated to reflect the most preferred method, or clarify that additional steps are needed to manage the environment variable? The current documentation is sparse and simply assumes that exporting will work without any further steps.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/meraki/dashboard-api-python/issues/150, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5EUKXZK6CIAHB5S75OV5TTDDZ3FANCNFSM4ZAYFFUA .

kmanwar89 commented 3 years ago

Hi there,

I'm not entirely sure what happened, but while trying to reproduce this for a friend today at work, I couldn't re-create the behavior. I spun up a fresh Ubuntu VM to see if I can reproduce it, but I can't. I can speculate on what might have happened, but I won't.

If this happens again, I will be sure to detail exactly what I did to produce the error. Thank you.