我试图在python库zeep的帮助下使用wsdl。它工作得很好,但我不知道如何从请求中获取数据。
我的代码:
# encoding=utf-8
from requests.auth import HTTPBasicAuth # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
from zeep import helpers
from zeep.transports import Transport
import logging.config
logging.config.dictConfig({
'version': 1,
'formatters': {
'verbose': {
'format': '%(name)s: %(message)s'
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'loggers': {
'zeep.transports': {
'level': 'DEBUG',
'propagate': True,
'handlers': ['console'],
},
}
})
wsdl = 'wsdl_url'
user = 'login'
password = 'password'
my_transport = Transport(http_auth=HTTPBasicAuth(user, password))
client = Client(
wsdl, transport=my_transport
)
result = client.service.FunctionName(...)
print result
结果,我得到了这个:
{
'schema': <Schema(location=None)>,
'_value_1': <Element {urn:schemas-microsoft-com:xml-diffgram- v1}diffgram at 0x104ec0098>
}
显然,这不是我想要的。多亏了记录,我可以看到,实际上我用信封得到了所需的信息:
我的问题是,如何访问信封内的数据(我需要部分显示在屏幕上的行顺序)
我也面临同样的问题。所以我就是这样做的。这不是最好的方法,但它可以是一个开始,我希望造物主原谅我。 另外,我刚刚开始学习python。
在此处克隆zeep项目: https://github.com/mvantellingen/python-zeep 去那个文件夹。
在transports.py中,将这一行添加到构造函数中(init):
然后在方法post中,在返回响应之前,添加以下行:
在此之后,通过执行
这应该在你的virtualenv中(如果你正在使用的话)
所以在你的代码中,你可以打印
希望这有帮助
使用Zeep版本2.4.0,我可以通过向客户机传递raw_response选项来获得原始响应。这告诉客户端返回请求响应对象。
下面是示例代码:
相关问题 更多 >
编程相关推荐