Search code examples
pythonazureazure-storageazure-queues

How to handle exceptions in Python Azure Storage SDK


I am trying to implement a job which reads from Azure Queue and writes into db. occasionally some errors are raised from the Azure server such as timeout, server busy etc. How to handle such errors in the code, I tried ti run the code in a try catch loop but, I am not able to identify Azure errors? I triedn to import WindowsAzureError from azure , but it doesn't work (no such module to import)?

Which is a good way to handle errors in this case?


Solution

  • If you're using 0.30+ all errors that occur after the request to the service has been will extend from AzureException. AzureException can be found in the azure.common package which Azure storage takes a dependency on. Errors which are thrown if invalid args are passed to a method (ex None for the queue name) might not extend from this and will be standard Python exception like ValueError.