Michael
Michael

Reputation: 99

azure-storage-python - Exception handling with create_blob_from_path

If for some reason the create_blob_from_path method runs into issues, what would be the proper way to handle the exception? As in, when you are writing your 'except' block, it would be except ??what?? as e: ? I want to be able to handle that exception when a blob upload fails so it can email me via sendmail so I know a backup that is attempting to be offloaded to Azure storage has failed.

Thank you!

Upvotes: 1

Views: 2542

Answers (1)

Peter Pan
Peter Pan

Reputation: 24128

I looked for & searched some exception names on the source codes of Azure Python Storage SDK, there are not any exceptions defined about failure of uploading blob. However, per my experience, Azure Storage SDK for Python wrapped REST APIs of Storage Services via the python package requests to do related operations. So any failure will cause the requests exceptions, you can try to catch the requests root exception requests.exceptions.RequestException as below to do the next action like sendmail.

import requests

try:
    blobservice.create_blob_from_path(container_name, blob_name, file_path)
except requests.exceptions.RequestException:
    sendmain(...)

Upvotes: 1

Related Questions