简体   繁体   English

如何处理Python Azure Storage SDK中的异常

[英]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. 我正在尝试实现从Azure Queue读取并写入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? 偶尔会从Azure服务器引发一些错误,例如超时,服务器忙等。如何在代码中处理此类错误,我尝试在try catch循环中运行代码,但是,我无法识别Azure错误? I triedn to import WindowsAzureError from azure , but it doesn't work (no such module to import)? 我试图从azure导入WindowsAzureError,但它不起作用(没有这样的模块导入)?

Which is a good way to handle errors in this case? 在这种情况下,哪种方法可以处理错误?

If you're using 0.30+ all errors that occur after the request to the service has been will extend from AzureException. 如果您使用0.30+,则在对服务的请求之后发生的所有错误都将从AzureException扩展。 AzureException can be found in the azure.common package which Azure storage takes a dependency on. AzureException可以在Azure存储依赖的azure.common包中找到。 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. 如果将无效的args传递给方法(队列名称为none),则抛出的错误可能不会从此扩展,并且将是像ValueError这样的标准Python异常。

Thanks @Terran, 谢谢@Terran,

exception azure.common.AzureConflictHttpError(message, status_code) Bases: azure.common.AzureHttpError 异常azure.common.AzureConflictHttpError(message,status_code)基础:azure.common.AzureHttpError

exception azure.common.AzureException Bases: exceptions.Exception 异常azure.common.AzureException Bases:exceptions.Exception

exception azure.common.AzureHttpError(message, status_code) Bases: azure.common.AzureException 异常azure.common.AzureHttpError(message,status_code)基础:azure.common.AzureException

exception azure.common.AzureMissingResourceHttpError(message, status_code) Bases: azure.common.AzureHttpError 异常azure.common.AzureMissingResourceHttpError(message,status_code)基础:azure.common.AzureHttpError

This helped me.. http://azure-sdk-for-python.readthedocs.org/en/latest/ref/azure.common.html 这帮了我.. http://azure-sdk-for-python.readthedocs.org/en/latest/ref/azure.common.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM