【发布时间】:2021-12-22 10:53:04
【问题描述】:
我必须查询第三方 SOAP 端点。这个端点有时有一个附件,有时它只有纯 XML。在收到回复并进行检查之前,我无法知道会发生什么。
之前的开发者做了这样的事情:
result = client.service.download(
# parameters
)
# TODO remove unresolved reference when I understand zeep library better
# noinspection PyUnresolvedReferences
message_type = zeep.wsdl.attachments.MessagePack
if isinstance(result, message_type):
content = str(result.attachments[0].content, encoding='utf-8')
else:
content = serialize_object(result)["fileContents"]
我想要一种方法来确定我得到的响应类型,而不必抑制来自我的 IDE 的“未解决的引用”投诉。避免使用异常进行流控制也很好,即在调用result.root 时处理AttributeError。
Zeep 是否有一些规范的方法来确定响应是否有附件?我很难在文档中找到类似的东西。
【问题讨论】: