我正在尝试使用 python sdk 为 smartsheet aPI 编写 try except 块,特别是在 API 对调用的响应返回错误对象而不是通常的索引结果对象的情况下。有人可以解释我会遇到什么样的异常。我不确定是否必须创建自己的自定义异常,或者是否有某种方法可以捕获异常。API 文档讨论了错误消息,而不是处理。如果有人可以分享一些相同的简单示例,那就太好了。
1 回答
0
知道成功响应的样子,您可以尝试检查错误响应。例如,使用无效的 rowId 运行 get_row 将导致此错误:
{"requestResponse": null, "result": {"code": 1006, "name": "NotFoundError", "recommendation": "Do not retry without fixing the problem. Hint: Verify that specified URI is correct. If the URI contains an object ID, verify that the object ID is correct and that the requester has access to the corresponding object in Smartsheet.", "shouldRetry": false, "message": "Not Found", "statusCode": 404}}
看到 requestResponse 为空,您可以检查结果对象以了解要在 Smartsheet API 文档中查找的代码。此外,还有一个推荐参数给出了后续步骤。
于 2016-09-13T23:37:33.047 回答