I am trying to delete a blob from our Azure container. I am able to connect to it and list all the blobs following the code in this question: Upload and Delete Azure Storage Blob using azure-storage-blob or azure-storage
CONNECT_STR = "DefaultEndpointsProtocol=https;AccountName=XXX;AccountKey=XXXXXXXXXX;EndpointSuffix=core.windows.net"
CONTAINER_NAME = "containername/"
blob_name = "productionmap/oursoftware/intended_blob_to_use.csv"
container_client = ContainerClient.from_connection_string(conn_str=CONNECT_STR, container_name=CONTAINER_NAME)
# Delete blob
container_client.delete_blob(blob=blob_name)
I am able to list all the blobs. I have tried to use a for loop to loop through the blobs and getting the specific blob to delete:
for x in bloblist:
if x.name == 'intended_blob_to_use.csv':
print(x.name)
container_client.delete_blob(blob=x)
Above code is able to get the specific blobs name through the print but cannot delete it. Therefore it shouldn't have to do with the name of my file. The error message I receive is:
Traceback (most recent call last):
File "/tmp/interpreter-input-038d73c4-068f-421b-b349-2f61f486a36b.tmp", line 25, in <module>
container_client.delete_blob(ourblobfile)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/core/tracing/decorator.py", line 73, in wrapper_use_tracer
return func(*args, **kwargs)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_container_client.py", line 1060, in delete_blob
**kwargs)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/core/tracing/decorator.py", line 73, in wrapper_use_tracer
return func(*args, **kwargs)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_blob_client.py", line 1106, in delete_blob
process_storage_error(error)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_shared/response_handlers.py", line 181, in process_storage_error
exec("raise error from None") # pylint: disable=exec-used # nosec
File "<string>", line 1, in <module>
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_blob_client.py", line 1104, in delete_blob
self._client.blob.delete(**options)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/storage/blob/_generated/operations/_blob_operations.py", line 589, in delete
map_error(status_code=response.status_code, response=response, error_map=error_map)
File "/usr/share/tomcat8/.local/lib/python3.6/site-packages/azure/core/exceptions.py", line 105, in map_error
raise error
azure.core.exceptions.ResourceNotFoundError: The specified blob does not exist.
RequestId:ccd2f1dd-a01e-0078-4989-4d431e000000
Time:2022-04-11T09:49:05.7447809Z
ErrorCode:BlobNotFound
Content: <?xml version="1.0" encoding="utf-8"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.
RequestId:ccd2f1dd-a01e-0078-4989-4d431e000000
Time:2022-04-11T09:49:05.7447809Z</Message></Error>`
How come I cannot delete it? I am passing a key through the connection string and that user has "Owner" set on the storage.