Skip to content
Advertisement

Handle exception for Blob not present scenario in Azure blob delete client in Python

I have thousands of blobs in the container and have a list of blobs to be deleted fetched from some db.

Now, there is no guarantee that the id/name present in the list is present in the blob. so want to do a deleteIfExist kind of a scenario and

error it throws when blob is not present is NOT : azure.core.exceptions.ResourceNotFoundError: Operation which i can write an exception block for.

It throws something generic like : azure.storage.blob._shared.response_handlers.PartialBatchErrorException: There is a partial failure in the batch operation.

Code below :

JavaScript

Advertisement

Answer

Take a look at the following code:

JavaScript

Essentially whenever there an exception of type PartialBatchErrorException, it’s parts property will have the details about the result of each operation in the batch. You can check the status code of each operation to determine if it was successful (status code 202) or failed (other status code). If the status code is 404 (Not Found), you can assume that the blob does not exist.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement