Vikas Gautam
Vikas Gautam

Reputation: 249

Azure authentication failed using python sdk

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

Upvotes: 1

Views: 994

Answers (1)

Jay Gong
Jay Gong

Reputation: 23792

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.

Upvotes: 1

Related Questions