所以我有以下 Python3 脚本来列出所有虚拟机。
import os, json
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.resource import ResourceManagementClient, SubscriptionClient
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id="xxx",
secret="xxx",
tenant="xxx"
)
resource_client = ResourceManagementClient(credentials, "my-subscription")
compute_client = ComputeManagementClient(credentials, "my-subscription")
network_client = NetworkManagementClient(credentials, "my-subscription")
for vm in compute_client.virtual_machines.list_all():
print("\tVM: {}".format(vm.name))
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,我收到以下错误:
Traceback (most recent call last):
File "/Users/me/a/azure-test.py", line 17, in <module>
for vm in compute_client.virtual_machines.list_all():
...
File "/usr/local/lib/python3.8/site-packages/azure/core/pipeline/policies/_authentication.py", line 93, in on_request
self._token = self._credential.get_token(*self._scopes)
AttributeError: 'ServicePrincipalCredentials' object has no attribute …Run Code Online (Sandbox Code Playgroud) python azure python-3.x azure-virtual-machine azure-sdk-python
我正在尝试使用azure-python-sdk列出 Azure 帐户中的订阅。
我已点击文档中的此链接。
from azure.mgmt.subscription import SubscriptionClient
from msrestazure.azure_active_directory import UserPassCredentials
credentials = UserPassCredentials(username='xxxx', password='xxxx')
sub_client = SubscriptionClient(credentials)
subs = [sub.as_dict() for sub in sub_client.subscriptions.list()]
print(subs)
Run Code Online (Sandbox Code Playgroud)
它应该返回订阅列表。但是,每次尝试上述代码时,我都只看到返回空列表。有人可以帮忙吗?
我编写了一个运行 Python3 的 Azure 函数来简单地打开 Azure VM。
该函数应用程序具有系统分配的托管标识,我已为其授予 VM 贡献者角色。为了让该函数使用托管标识,我使用了 DefaultAzureCredential() 类。
我得到的错误是:
Exception: AttributeError: 'DefaultAzureCredential' object has no attribute 'signed_session'
我已经进行了大量的研究,但似乎找不到解决方案。
这是相关的代码:
from azure.identity import DefaultAzureCredential
credentials = DefaultAzureCredential()
compute_client = ComputeManagementClient(credentials, subscription_id)
# Starting the VM
print('\nStarting VM ' + VM_NAME)
vm_start = compute_client.virtual_machines.start(
RG_NAME, VM_NAME)
vm_start.wait()
Run Code Online (Sandbox Code Playgroud)
请原谅我,我只是 Python 新手,但对学习非常感兴趣。
我正在尝试通过 python 访问 Azure 表存储。
按照这里的旧演练:https : //docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-python#install-the-azure-storage-sdk-for- Python
但是它专门为Azure 表引用的 Python SDK ( https://github.com/Azure/azure-storage-python ) 已被移动/弃用,以支持 Azure Cosmos DB SDK。
在弃用说明中,他们说要使用这个 SDK:https : //github.com/Azure/azure-cosmosdb-python
在该 SDK 的文档中,他们将您推荐给https://azure.microsoft.com/en-us/develop/python/
在该页面上的表存储和链接中,它会将您引回到第一个链接 (!!)
============
1) 我想要做的就是使用 Python SDK查询传统的Azure 表存储(不是 CosmosDB)
2) 理想情况下,Python SDK 还包括 Azure 表的加密/解密功能。
我错过了什么/那个python SDK是否仍然存在于任何地方?
注意: 我看到https://github.com/Azure/azure-cosmosdb-python/tree/master/azure-cosmosdb-table 但这个 SDK 似乎需要 CosmosDB 部署——它无法连接到传统的 AzureTables。我的理解不正确吗?
谢谢你的尽心帮助。
我需要创建一个服务主体并通过 SDK 为其分配一个新角色Python。我目前正在执行此stackoverflow 问题中列出的步骤。
我目前正在进行角色分配,但我陷入了“我需要输入 a ”的步骤principal_id。例如,这里根据需要创建一个新的角色分配。principal id我在门户中哪里可以找到这项服务Azure?是在门户-> Active Directory -> 应用程序注册-> 我的应用程序下吗appId?objectIdAzure
我在自托管代理上有一个 Azure Pipeline我使用此任务
- task: AzureCLI@2
displayName: Azure CLI task with Python SDK
inputs:
azureSubscription: 'SUBSCRIPTION-SERVICE-CONNECTION'
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
python ./magic-script.py
Run Code Online (Sandbox Code Playgroud)
这样我就可以使用凭据来验证Azure Python SDK:
client = get_client_from_cli_profile(GraphRbacManagementClient)
Run Code Online (Sandbox Code Playgroud)
当我将此过程转移到MS 托管代理时,我收到此错误:
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/common/client_factory.py", line 85, in get_client_from_cli_profile
with_tenant=True,
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/common/credentials.py", line 98, in get_azure_cli_credentials
cred, subscription_id, tenant_id = profile.get_login_credentials(resource=resource)
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/cli/core/_profile.py", line 335, in get_login_credentials
credential = self._create_credential(account, client_id=client_id)
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/cli/core/_profile.py", line 592, in _create_credential
return identity.get_service_principal_credential(username_or_sp_id)
File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/azure/cli/core/auth/identity.py", line 185, in get_service_principal_credential
entry …Run Code Online (Sandbox Code Playgroud) 我使用下面的应用程序见解 python sdk 在应用程序见解资源中发送我的自定义指标。
https://github.com/Microsoft/ApplicationInsights-Python
现在,当我想要检索它时,我只能找到基于 Rest API 的方法来检索它。
https://dev.applicationinsights.io/documentation/Using-the-API/Metrics
是否有基于 RestAPI 的curl 或 http 请求的替代方案 - 在应用程序洞察 python sdk 中?
我一直在参考文档https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python。我无法找到将文件从一个容器复制/移动到另一个容器的正确 API。假设我有两个容器 A 和 B。现在我想将一个 blob 从 A 复制到 B。我该如何实现呢?举个例子将不胜感激。
azure-core==1.1.1
azure-storage-blob==12.0.0
Run Code Online (Sandbox Code Playgroud)
注意:我已经经历过这个线程,它仅在旧版本的 SDK 中受支持。
python azure azure-storage azure-blob-storage azure-sdk-python
我当前正在编写一个可访问有关 Azure 虚拟机的详细信息的脚本。这是我到目前为止的代码:
"""
Instantiate the ComputeManagementClient with the appropriate credentials.
@return ComputeManagementClient object
"""
def get_access_to_virtual_machine():
subscription_id = key.SUBSCRIPTION_ID
credentials = DefaultAzureCredential(authority = AzureAuthorityHosts.AZURE_GOVERNMENT,
exclude_environment_credential = True,
exclude_managed_identity_credential = True,
exclude_shared_token_cache_credential = True)
client = KeyClient(vault_url = key.VAULT_URL, credential = credentials)
compute_client = ComputeManagementClient(credentials, subscription_id)
return compute_client
"""
Check to see if Azure Virtual Machine exists and the state of the virtual machine.
"""
def get_azure_vm(resource_group_name, virtual_machine_name):
compute_client = get_access_to_virtual_machine()
vm_data = compute_client.virtual_machines.get(resource_group_name,
virtual_machine_name,
expand = 'instanceView')
return vm_data …Run Code Online (Sandbox Code Playgroud) python azure azure-virtual-machine azure-sdk-python azure-functions
我的 BlobStorage 中有几千个视频文件,我将其设置为数据存储。此 Blob 存储每天晚上都会收到新文件,我需要拆分数据并将每个拆分注册为新版本的 AzureML 数据集。
这就是我进行数据分割的方式,只需获取 blob 路径并分割它们即可。
container_client = ContainerClient.from_connection_string(AZ_CONN_STR,'keymoments-clips')
blobs = container_client.list_blobs('soccer')
blobs = map(lambda x: Path(x['name']), blobs)
train_set, test_set = get_train_test(blobs, 0.75, 3, class_subset={'goal', 'hitWoodwork', 'penalty', 'redCard', 'contentiousRefereeDecision'})
valid_set, test_set = split_data(test_set, 0.5, 3)
Run Code Online (Sandbox Code Playgroud)
train_set, test_set, valid_set只是包含 blob 存储路径和类的 nx2 numpy 数组。
这是我尝试创建数据集的新版本时的情况:
datastore = Datastore.get(workspace, 'clips_datastore')
dataset_train = Dataset.File.from_files([(datastore, b) for b, _ in train_set[:4]], validate=True, partition_format='**/{class_label}/*.mp4')
dataset_train.register(workspace, 'train_video_clips', create_new_version=True)
Run Code Online (Sandbox Code Playgroud)
即使只有 4 个路径,数据集创建似乎也会无限期挂起,这怎么可能?我在文档中看到提供一个列表Tuple[datastore, path]是完全可以的。你知道为什么吗?
谢谢
azure-sdk-python ×10
azure ×6
python ×5
azure-machine-learning-service ×1
azureportal ×1
python-3.x ×1