简体   繁体   English

如何使用 Zeep 和 Python 3.7 捕获错误

[英]How do I catch errors using Zeep and Python 3.7

I am learning how to use Zeep as my soap client.我正在学习如何使用 Zeep 作为我的肥皂客户端。 I am able to connect to a WSDL and view services, however, I am stuck on how to catch all possible exceptions.我能够连接到 WSDL 并查看服务,但是,我被困在如何捕获所有可能的异常上。 I am only able to catch KeyError.我只能捕获 KeyError。 I want to be able to catch a few more:我希望能够捕捉更多:

Basically something similar to the below http client example:基本上类似于下面的http客户端示例:

except (http.client.HTTPException, ValueError, KeyError, AttributeError) as e除了 (http.client.HTTPException, ValueError, KeyError, AttributeError) 作为 e

I would want to use try.....except我想用 try.....except

try:
    session = Session()
    session.auth = HttpNtlmAuth(username, password)

    request_data = {
    }
    client = Client(wsdl, transport=Transport(session=session))
    response = client.service.GetPendingBills(**request_data)
    billobj = json.loads(response)
    print(billobj)
    bills = (len(billobj["Bills"]))
except KeyError as e:
    bills = 0

I decided to import requests and handle the exceptions as indicated below:我决定导入请求并处理如下所示的异常:

except (requests.exceptions.HTTPError, KeyError, TimeoutError) as e除了 (requests.exceptions.HTTPError, KeyError, TimeoutError) as e

Thanks谢谢

Maybe this is too late, but you can import zeep.exceptions and handle all kinds of exceptions that you have that way.也许这为时已晚,但您可以导入 zeep.exceptions 并以这种方式处理各种异常。 You just need to check the exception and catch it as you have demonstrated above.您只需要按照上面的演示检查异常并捕获它。

Solution is shown in this documentation解决方案显示在本文档中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM