这是我从azure获得的exception的内容(如果类型为exceptionazure.common.AzureHttpError在python中):
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:a8ecea4d-001e-0112-76b0-9a717b000000
Time:2018-01-31T16:31:20.9812336Z</Message><AuthenticationErrorDetail>Signature did not match. String to sign used was masking_it_intentionally
rwdlacup
bfqt
sco
2018-01-03T21:19:36Z
2018-03-09T05:19:36Z
https
2017-04-17
</AuthenticationErrorDetail></Error>
异常的主体似乎是一些字符串,后面是xml样式的信息块。我想从xml数据中提取一个特定的键,例如AuthenticationErrorDetail
(这样我就可以根据它的值编写一些代码)
我想用最简单的方法来完成,也就是说,我不想自己解析异常体。因为如果我决定自己解析xml,我将如何决定xml从哪里开始呢?(是的,我可以搜索字符串<?xml
,但我想避免它)。在
那么,我该怎么做呢?在
我希望已经有一些库/工具/解析器/对象来实现这一点。在
AzureHttpError
有一些可以使用的属性:status_code
、error_code
和{我不知道这是否是最好的方法,我在文档中找不到任何东西,所以使用
err.__dict__
和err.__dir__()
来解决问题,但它确实有效,而且肯定比解析错误字符串要好。在相关问题 更多 >
编程相关推荐