Azure function: AttributeError: 'SubscriptionClient' object has no attribute 'subscriptions'
Azure function: AttributeError: 'SubscriptionClient' object has no attribute 'subscriptions'
我正在使用 Azure 函数应用程序,持久函数用于列出订阅并通过每个子来执行一些过程。我的代码工作正常,直到几天前它因出现此错误而停止工作:
AttributeError: 'SubscriptionClient' object has no attribute 'subscriptions'
Stack: File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 405, in _handle__invocation_request
invocation_id, fi_context, fi.func, args)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 612, in _run_sync_func
func)(params)
File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper
result = function(**args)
File "/home/site/wwwroot/Upgrade/__init__.py", line 38, in main
for sub in sub_client.subscriptions.list():
at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 96
at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82
at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
我找不到它丢失了什么。
这是我的代码:
init.py
import logging
import subprocess
import json
import os
from azure.cli.core import get_default_cli
from azure.mgmt.containerservice import ContainerServiceClient
from azure.identity import ClientSecretCredential
from azure.mgmt.subscription import SubscriptionClient
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.containerservice.models import (ManagedClusterAgentPoolProfile, ManagedCluster)
def main(env: str) -> str:
logging.info('Python aks-upgrade function processed a request.')
#print("Environment:", env)
if env:
try:
credential = ClientSecretCredential(
tenant_id='mytenantid',
client_id = os.environ["function_client_id"],
client_secret= os.environ["function_client_secret"]
)
sub_client = SubscriptionClient(credential=credential)
except:
print("An exception occurred")
#sub_client.subscriptions.list()
print("Listing Subscriptions....")
for sub in sub_client.subscriptions.list():
print("Sub_Name:", sub.display_name, "Environment:", env)
requirements.txt
azure-functions
azure-functions-durable
azure-cli
azure-identity
azure-mgmt-containerservice~=16.1.0
azure-mgmt-subscription
azure-mgmt-resource==19.0.0
requests~=2.25.1
我创建了一个具有服务主体的应用程序,该应用程序具有 Reader 访问权限以及对 AKS 的一些访问权限,client_id 和 client_secret 是在此应用程序下生成的。
如果有人能帮助解决这个问题,我将不胜感激。
我只是第一次尝试使用 SubscriptionClient,运行 遇到了同样的问题,很高兴不仅仅是我。
我确实发现他们在 2021 年 11 月 25 日发布了该模块的新版本(请参阅此处的发行说明:https://github.com/Azure/azure-sdk-for-python/releases/tag/azure-mgmt-subscription_2.0.0),其中列出了“已删除的操作组 SubscriptionsOperations”的重大更改.该文档似乎没有反映这一点,并且不清楚您应该做什么来列出所有订阅。
我通过将 azure-mgmt-subscription 固定到 1.0.0 使其工作。
我正在使用 Azure 函数应用程序,持久函数用于列出订阅并通过每个子来执行一些过程。我的代码工作正常,直到几天前它因出现此错误而停止工作:
AttributeError: 'SubscriptionClient' object has no attribute 'subscriptions'
Stack: File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 405, in _handle__invocation_request
invocation_id, fi_context, fi.func, args)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 612, in _run_sync_func
func)(params)
File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper
result = function(**args)
File "/home/site/wwwroot/Upgrade/__init__.py", line 38, in main
for sub in sub_client.subscriptions.list():
at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 96
at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82
at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /src/azure-functions-host/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
我找不到它丢失了什么。
这是我的代码:
init.py
import logging
import subprocess
import json
import os
from azure.cli.core import get_default_cli
from azure.mgmt.containerservice import ContainerServiceClient
from azure.identity import ClientSecretCredential
from azure.mgmt.subscription import SubscriptionClient
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.containerservice.models import (ManagedClusterAgentPoolProfile, ManagedCluster)
def main(env: str) -> str:
logging.info('Python aks-upgrade function processed a request.')
#print("Environment:", env)
if env:
try:
credential = ClientSecretCredential(
tenant_id='mytenantid',
client_id = os.environ["function_client_id"],
client_secret= os.environ["function_client_secret"]
)
sub_client = SubscriptionClient(credential=credential)
except:
print("An exception occurred")
#sub_client.subscriptions.list()
print("Listing Subscriptions....")
for sub in sub_client.subscriptions.list():
print("Sub_Name:", sub.display_name, "Environment:", env)
requirements.txt
azure-functions
azure-functions-durable
azure-cli
azure-identity
azure-mgmt-containerservice~=16.1.0
azure-mgmt-subscription
azure-mgmt-resource==19.0.0
requests~=2.25.1
我创建了一个具有服务主体的应用程序,该应用程序具有 Reader 访问权限以及对 AKS 的一些访问权限,client_id 和 client_secret 是在此应用程序下生成的。
如果有人能帮助解决这个问题,我将不胜感激。
我只是第一次尝试使用 SubscriptionClient,运行 遇到了同样的问题,很高兴不仅仅是我。
我确实发现他们在 2021 年 11 月 25 日发布了该模块的新版本(请参阅此处的发行说明:https://github.com/Azure/azure-sdk-for-python/releases/tag/azure-mgmt-subscription_2.0.0),其中列出了“已删除的操作组 SubscriptionsOperations”的重大更改.该文档似乎没有反映这一点,并且不清楚您应该做什么来列出所有订阅。
我通过将 azure-mgmt-subscription 固定到 1.0.0 使其工作。