【发布时间】:2020-03-28 22:19:38
【问题描述】:
我正在尝试使用 python 在 azure 存储中创建 blob 容器。我正在使用MSDN 提供的文档将 azure blob 存储集成到我的 python 程序中。
代码如下:
connectStr = <connString>
blobServiceClient = BlobServiceClient.from_connection_string(connectStr)
containerName = "quickstart-azureStorage"
localFileName = "quickstart-1.txt"
blobClient = blobServiceClient.create_container(containerName)
create_container() 第一次创建 blob 容器,但第二次出现错误。
如果 blob 容器不存在,我想创建它。如果存在,则使用现有的 blob 容器
我正在使用 azure 存储库版本 12.0.0。即azure-storage-blob==12.0.0
我知道我们可以使用以下代码为该容器中存在的 blob 执行此操作,但我没有找到任何用于创建容器本身的内容。
检查 blob 是否存在:
blobClient = blobServiceClient.get_blob_client(container=containerName, blob=localFileName)
if blobClient:
print("blob already exists")
else:
print("blob not exists")
例外:
RequestId:<requestId>
Time:2019-12-04T06:59:03.1459600Z
ErrorCode:ContainerAlreadyExists
Error:None
【问题讨论】:
标签: python azure azure-storage azure-blob-storage