如何在Azure Python函数中连接Azure TableService响应?
我不熟悉Python错误处理 使用Azure表存储作为Python Azure函数的配置表。要查找表中的特定行,我使用构造函数如何在Azure Python函数中连接Azure TableService响应?,python,error-handling,azure-functions,azure-cosmosdb,Python,Error Handling,Azure Functions,Azure Cosmosdb,我不熟悉Python错误处理 使用Azure表存储作为Python Azure函数的配置表。要查找表中的特定行,我使用构造函数 from azure.cosmosdb.table.tableservice import TableService from azure.cosmosdb.table.models import Entity TableName = "Table1" PartitionKey = 'test' RowKey = '123' table_serv
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity
TableName = "Table1"
PartitionKey = 'test'
RowKey = '123'
table_service.get_entity(TableName, PartitionKey, RowKey)
如果未找到实体(行),则结果为:
Client-Request-ID = 123-xzy
Receiving Response: Server
Timestamp = Thu, 19 Nov 2020 20: 43: 23 GMT,
Server-Request-ID = xyz-123,
HTTP Status Code = 404,
Message = Not Found,
Headers = {
'cache-control': 'no-cache',
'transfer-encoding': 'chunked',
'content-type': 'application/json;odata=minimalmetadata;streaming=true;charset=utf-8',
'server': 'Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0',
'x-ms-request-id': 'xxx-xxx',
'x-ms-version': '2018-03-28',
'x-content-type-options': 'nosniff',
'date': 'Thu, 19 Nov 2020 20:43:23 GMT'
}
如何使用Python访问响应中的未找到消息?
尝试以下操作:
from azure.common import AzureMissingResourceHttpError
try:
table_service.get_entity(TableName, PartitionKey, RowKey)
except AzureMissingResourceHttpError as e:
exception_content = e.args[0]
print("===values you need===")
print(exception_content[:exception_content.find("\n")])
print("===all exception content===")
print(e.status_code)
print(exception_content)
结果:
这太好了。谢谢你的见解。你能看一下上面的编辑1:并指导示例吗?我不太明白如何获取异常输出并控制
返回
@ericOnline,谢谢您的回复,因为这个问题已经结束,您能打开另一个问题并让我知道链接吗?我会尽快回复你。感谢您的持续帮助。@Eric在线,欢迎,我的同事Hury似乎已经回答了您:)