Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

MSIAuthentication could not retrieve a token #149

Closed
shawnswlin opened this issue Jun 3, 2020 · 2 comments
Closed

MSIAuthentication could not retrieve a token #149

shawnswlin opened this issue Jun 3, 2020 · 2 comments

Comments

@shawnswlin
Copy link

shawnswlin commented Jun 3, 2020

Hi,

I'm using Azure Function with Python and managed-identity, but noticed that a MSI: Failed to retrieve a token exception appears many times. Is there any workaround or new build could fix this problem?

Package version:

msrestazure==0.6.1

Trace back:

Exception while executing function: Functions.AzureTimerTrigger Result: Failure
Exception: RuntimeError: MSI: Failed to retrieve a token from 'http://localhost:8081/msi/token/?resource=https://management.core.windows.net/&api-version=2017-09-01' with an error of 'HTTPConnectionPool(host='localhost', port=8081): Max retries exceeded with url: /msi/token/?resource=https://management.core.windows.net/&api-version=2017-09-01 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7feee2e160f0>: Failed to establish a new connection: [Errno 111] Connection refused',))'.
Stack:   File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 315, in _handle__invocation_request
    self.__run_sync_func, invocation_id, fi.func, args)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 434, in __run_sync_func
    return func(**params)
  File "/home/site/wwwroot/AzureTimerTrigger/main.py", line 84, in main
    compute_client = create_azure_client(ComputeManagementClient, virtual_appliance_subscription)
  File "/home/site/wwwroot/AzureTimerTrigger/main.py", line 306, in create_azure_client
    credentials = MSIAuthentication()
  File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 592, in __init__
    self.set_token()
  File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 596, in set_token
    self.scheme, _, self.token = get_msi_token_webapp(self.resource, self.msi_conf)
  File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 546, in get_msi_token_webapp
    raise RuntimeError(err_msg)
@shawnswlin
Copy link
Author

A similar issue has fixed for JS Azure/azure-sdk-for-js#4631

@lmazuel
Copy link
Member

lmazuel commented Dec 30, 2020

Closing, since the recommended approach now is officially to use azure-identity to pull MSI token

@lmazuel lmazuel closed this as completed Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants