I am trying to create blob container in azure storage using python. I am using documentation provided by MSDN to integrate azure blob storage in my python program.
Here is the code:
connectStr = <connString>
blobServiceClient = BlobServiceClient.from_connection_string(connectStr)
containerName = "quickstart-azureStorage"
localFileName = "quickstart-1.txt"
blobClient = blobServiceClient.create_container(containerName)
create_container()
is creating blob container first time, but it is giving me error second time.
I want to create blob container if it does not exists. If it exist then use existing blob container
I am using azure storage library version 12.0.0. i.e azure-storage-blob==12.0.0
I know we can do it for blob present in that container using below code, but I did not find anything for creating container itself.
Check blob exists or not:
blobClient = blobServiceClient.get_blob_client(container=containerName, blob=localFileName)
if blobClient:
print("blob already exists")
else:
print("blob not exists")
Exception:
RequestId:<requestId>
Time:2019-12-04T06:59:03.1459600Z
ErrorCode:ContainerAlreadyExists
Error:None
CreateIfNotExists()
(Available in C#) learn.microsoft.com/en-us/dotnet/api/… – Sophiasophie