Search code examples
pythonazureazure-management-apiazure-vm-role

Azure Python SDK Authentication Error


I am trying to stop a virtual machine in the azure cloud using the azure-python-sdk. I am following this page https://github.com/Azure-Samples/virtual-machines-python-manage and I have created an Azure active directory application by following this link, https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal.

As a first step I am trying to authenticate using a call to ServicePrincipalCredentials passing client_id, secret, and tenant, but the connection throws the following error, 'Keyring cache token has failed: (1783, 'CredWrite', 'The stub received bad data')'

The application has a Virtual Machine Contributor permission setup. Is this a permission issue?


Solution

  • Keyring is an optional sub-system that does not impact at all the Authentication. It's intended to store your token in a way that you can re-instanciate the credentials even if the Python process is gone, without talking again to AD. This does not block Authentication if the credentials is valid, this is just a warning log that if your Python process ends, you won't be able to re-create the Credentials class without re-asking a token to AD.

    If you have a stacktrace of exception that explicitly says that this was blocking the authentication to work, please open an issue here: https://github.com/Azure/msrestazure-for-python/issues

    (I own this code and lib at Microsoft and wrote the articles you mention)

    Edit: Starting msrestazure 0.5.0, keyring support has been removed.