[英]How to handle Azure Python Function exception handling?
我是 Python 异常处理的新手。 我如何正确try
以下操作, except
.get_entity
失败,但如果Status 200
则通过?
这是我所在的位置:
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity
from azure.common import AzureMissingResourceHttpError
def get_table_row(TableName, PartitionKey, RowKey):
try:
table_lookup = table_service.get_entity(TableName, PartitionKey, RowKey)
except AzureMissingResourceHttpError as e:
logging.error(f'#### Status Code: {e.status_code} ####')
finally:
if e.status_code == 200:
return table_lookup
else:
logging.error(f'#### Status Code: {e.status_code} ####')
data = get_table_row(TableName, PartitionKey, RowKey)
您可以更改您的代码,如下所示:
def get_table_row(TableName, PartitionKey, RowKey):
try:
table_lookup = table_service.get_entity(TableName, PartitionKey, RowKey)
except AzureMissingResourceHttpError as e:
if e.status_code == 200:
return table_lookup
else:
logging.error(f'#### Status Code: {e.status_code} ####')
return "whatever you want"
else:
return table_lookup
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.