简体   繁体   English

如何从zeep python库解析soap Fault.detail(lxml.etree._Element)

[英]How parse soap Fault.detail(lxml.etree._Element) from zeep python library

I'm trying get error detail, when I'm calling soap service with zeep. 当我使用zeep调用soap服务时,我尝试获取错误详细信息。

How parse zeep.exceptions.Fault.detail? 如何解析zeep.exceptions.Fault.detail? It's return lxml.etree._Element. 返回lxml.etree._Element。

I'm using this code: 我正在使用此代码:

try:
    client = Client(wsdl=self.__wsdl)
    response = client.service.CustomerInformation(CustomerInformationService=self.service, faultStyle='wsdl')
except Fault as error:
    detail = error.detail
    # parse detail here

Here is response XML: 这是响应XML:

<?xml version="1.0" ?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Body >
        <soap-env:Fault  >
            <faultcode>soap-env:Client</faultcode>
            <faultstring>Client Error</faultstring>
            <detail>
                <ouaf:Fault xmlns:ouaf="urn:oracle:ouaf">
                    <ResponseStatus>F</ResponseStatus>
                    <ResponseCode>2013</ResponseCode>
                    <ResponseText>
                            Error while executing the request:
                            (Server Message)
                                Category: 90006
                                Number: 32200
                                Call Sequence: 
                                Program Name: CustomerInformationService
                                Text: The personal account was not found: 9134211141
                                Description:  
                                Table: null
                                Field: null
                    </ResponseText>
                    <ResponseData numParm="1"  text="The personal account was not found: 9134211141"  category="90006"  number="32200"  parm1="9134211141"  />
                </ouaf:Fault>
            </detail>
        </soap-env:Fault>
    </soap-env:Body >
</soap-env:Envelope>

Diffinition of 'Fault' type from xml data exist in my wsdl. 我的wsdl中存在来自xml数据的“故障”类型区分。

I know this is an old question but looking for the answer got me here and now I also know how to do it. 我知道这是一个老问题,但是寻找答案使我到了这里,现在我也知道该怎么做。

The URL to wsdl in the example is made up as well as the credentials. 该示例中wsdl的URL以及凭据组成。

import zeep

url_to_wsdl = 'www.some_SOAP_site.com/soap?wsdl'

client = zeep.Client(url_to_wsdl)

credentials = {
    'login' : 'my_login',
    'pass' : 'my_pass'
}

my_query = "SELECT COLUMN1 FROM TABLE1"

try:
    client.service.query(my_query)
except zeep.exceptions.Fault as fault:
    parsed_fault_detail = client.wsdl.types.deserialize(fault.detail[0])

print(parsed_fault_detail)

Results in 结果是

{
    'errorCode': 'INVALID_SESSION',
    'errorMessage': 'Invalid session!'
}

Don't forget the [0] after fault.detail and try incrementing it to see if there are more error details. 不要在fault.detail之后忘记[0] ,并尝试将其递增以查看是否有更多错误详细信息。

You can use error.code or error.message to match with the error that you want to look for. 您可以使用error.codeerror.message来匹配您要查找的错误。

https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/exceptions.py#L53 https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/exceptions.py#L53

If you can't see anything in error.detail , consider sending a PR to the python-zeep project. 如果您在error.detail不到任何error.detail ,请考虑将PR发送到python-zeep项目。

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

相关问题 python lxml.etree._Element 到 JSON 或 dict - python lxml.etree._Element to JSON or dict 从lxml.etree._Element获取价值 - Get value from lxml.etree._Element LXML/Python - 遍历 lxml.etree._Element 列表 - LXML/Python - Looping over a list of lxml.etree._Element 解析lxml.etree._Element内容 - Parsing lxml.etree._Element contents 装饰lxml.etree._Element方法 - decorate lxml.etree._Element methods python lxml 3.3.5 - 加载代码时出错 - “ValueError:lxml.etree._Element的大小错误,请尝试重新编译” - python lxml 3.3.5 - error on loading code - “ValueError: lxml.etree._Element has the wrong size, try recompiling” lxml: cssselect(): AttributeError: &#39;lxml.etree._Element&#39; 对象没有属性 &#39;cssselect&#39; - lxml: cssselect(): AttributeError: 'lxml.etree._Element' object has no attribute 'cssselect' 令人难以置信的基本lxml问题:获取lxml.etree._Element的HTML /字符串内容? - Incredibly basic lxml questions: getting HTML/string content of lxml.etree._Element? 使用zeep库处理SOAP通信时如何处理python中的错误异常 - how to handle fault exception in python while using zeep library to handle SOAP communications 真的很奇怪……无法设置内置/扩展类型“lxml.etree._Element”的属性 - Really weird… can't set attributes of built-in/extension type 'lxml.etree._Element'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM