Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从zeep响应中提取XML_Python_Xml_Wsdl_Zeep - Fatal编程技术网

Python 如何从zeep响应中提取XML

Python 如何从zeep响应中提取XML,python,xml,wsdl,zeep,Python,Xml,Wsdl,Zeep,假设我使用python zeep对以下服务器执行查询: from zeep import Client wsdl_url = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL" client = Client(wsdl_url) result = client.service.ListOfContinentsByCode() 我希望看到从这个方法返回的原始XML,即从结果

假设我使用python zeep对以下服务器执行查询:

from zeep import Client

wsdl_url = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL"

client = Client(wsdl_url)
result = client.service.ListOfContinentsByCode()
我希望看到从这个方法返回的原始XML,即从结果中以某种方式提取它。这可能吗?怎么做?

这里(gzip的请求)


我想你正在寻找的是历史插件

从zeep.plugins导入历史插件
从zeep导入客户端
从lxml导入etree
wsdl_url=”http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL"
history=HistoryPlugin()
client=client(wsdl\uurl,插件=[历史])
client.service.CurrencyName('GBP')
您的\u pretty\u xml=etree.tostring(history.last\u收到[“信封”],encoding=“unicode”,pretty\u print=True)

如果您试图在
zeep
请求或响应中调试XML,则可以使用标准Python日志记录:

要查看发送到远程服务器的SOAP XML消息和接收到的响应,您可以为
zeep.transports
模块将Python记录器级别设置为DEBUG


不。这只是获取WSDL文档。我想从WSDL文档描述的SOAP方法中获取XML响应。它们是完全不同的东西。@Marc文章中的url指向xsd,xsd本身就是有效的xml。所以我认为您对wsdl文档感兴趣。现在我了解到您对zeep从连线中获得的xml数据感兴趣,并为您的通话创建了结果。这是真的吗?@Marc假设您想“查看”xml,您可以执行以下操作(基于zeep将请求用作传输的事实),您可以将请求的日志级别设置为详细,以便请求将打印出他感测的数据并返回。@Marc如果上述操作不起作用。你必须使用请求钩子它将使请求调用您的代码,从这里您将能够看到数据。如果由于响应未验证而导致zeep异常,请使用
settings=settings(strict=False)
import requests
r = equests.get('http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL')
if r.status_code == 200:
    print(r.content)
logging.config.dictConfig({
    ...
    'loggers': {
        'zeep.transports': {
            'level': 'DEBUG',
            'propagate': True,
            'handlers': ['console'],
        },
    },
})