1

I am new to azure and just stared learning, my aim is to get instance information using azure cli and python sdk, I am learning from official docs https://learn.microsoft.com/en-us/python/api/overview/azure/containerinstance?view=azure-python

I am trying to authenticate and get container info but script is not working, I have followed step 1 and 2. please help and if there is any other easy way to learn inform me.

here is code that i am using

from os import getenv
from azure.common.client_factory import get_client_from_auth_file
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
from azure.mgmt.resource.resources import ResourceManagementClient


AZURE_AUTH_LOCATION = 'C:\\Users\\gsc-30310\\PycharmProjects\\Azure\\my.azureauth'
auth_file_path = getenv('AZURE_AUTH_LOCATION', None)
if auth_file_path is not None:
    print("Authenticating with Azure using credentials in file at {0}"
          .format(auth_file_path))

    aciclient = get_client_from_auth_file(ContainerInstanceManagementClient)
    resclient = get_client_from_auth_file(ResourceManagementClient)
else:
    print("\nFailed to authenticate to Azure. Have you set the"
          " AZURE_AUTH_LOCATION environment variable?\n")
10
  • Please post the error that is returned or any information that could help in debugging the issue. Commented Dec 18, 2018 at 11:24
  • i am not getting error, my if statement is not running so program goes to else statement. Commented Dec 18, 2018 at 11:26
  • What is the value of auth_file_path before the if statement? Set a breakpoint there, or print the value. Commented Dec 18, 2018 at 11:37
  • it contains None value Commented Dec 18, 2018 at 12:32
  • I stored path directly like this auth_file_path = 'C:\\Users\\gsc-30310\\PycharmProjects\\Azure\\my.azureauth' and now i am getting KeyError: 'AZURE_AUTH_LOCATION' Commented Dec 18, 2018 at 12:36

1 Answer 1

1

Vikas. I followed the steps and set the AZURE_AUTH_LOCATION.

enter image description here

Then you need to restart your dev tool so that it could read your latest env value in new windows session. Otherwise,it will be always none.

Sign up to request clarification or add additional context in comments.

3 Comments

hi thanks, could you tell me how to set environment variable in pycharm?
@VikasGautam You mean you set the env var in code? I tested above answer just in windows advanced system settings.
@VikasGautam Great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.