使用Python检查ADSL gen2存储帐户是否存在的最佳方法是什么?

问题描述 投票:0回答:1

我的代码尝试读取许多存储帐户中的特定文件,并且在某些情况下存储帐户尚未创建。

在Python中检查存储帐户是否存在的最佳方法是什么?我目前使用以下代码。

from azure.storage.filedatalake import DataLakeServiceClient
from azure.identity import DefaultAzureCredential

credential=DefaultAzureCredential()
service_client=DataLakeServiceClient("https://somerandomaccountname.dfs.core.windows.net",credential=credential)
file_client=service_client.get_file_client(file_system="non_existing",file_path="file.name")
file_client.exists()

运行一分钟多后,返回 ServiceRequestError。

ServiceRequestError: <urllib3.connection.HTTPSConnection object at 0x0000021719BE13D0>: Failed to resolve 'somerandomaccountname.blob.core.windows.net' ([Errno 11001] getaddrinfo failed)

我可以捕获此错误,但想减少执行时间。有更好的建议吗?

python azure azure-storage-account
1个回答
0
投票

Python 管理 SDK 中有一个相当简单的功能来检查存储名称的可用性。如果该名称不可用,则该帐户存在。

https://learn.microsoft.com/en-us/rest/api/storagerp/storage-accounts/check-name-availability?view=rest-storagerp-2023-01-01&tabs=Python#storageaccountchecknameavailability

© www.soinside.com 2019 - 2024. All rights reserved.