python soap zeep模块获取结果 [英] python soap zeep module get result
问题描述
我从这样的SOAP API得到结果:
I'm getting a result from a SOAP API like that:
client = zeep.Client(wsdl=self.wsdl, transport=transport)
auth_header = lb.E("authenticate", self.login())
res = client.service.GetHouseProfile(region_id, page_number, reporting_period_id, _soapheaders=[auth_header])
现在我需要解析res并获得结果.
now I need to parse res and to get a result.
>>> dir(res)
['__class__', '__contains__', '__deepcopy__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__values__', '__weakref__', '_xsd_type']
>>> type(res)
<class 'zeep.objects.GetHouseProfileSFResponse'>
>>> print(res.__str__()[0:100])
{
'data': {
'item': [
{
'house_id': 6465882L,
如何从res中获取某个元素?
How to get a certain element from res?
所以我找到了方法.看来这不是标准决定,但确实可行:
So I found the way. Looks like not a standard decision but it works:
>>> res.__values__.get("data").__values__.get("item")[6].__values__.keys()
[u'house_id', u'house_profile_data', u'full_address', u'stage', u'state', u'emergency_date', u'emergency_number', u'emergency_reason', u'emergency_after', u'inn', u'files_info']
推荐答案
__values__
属性是私有的实现细节,您不应真正使用它.您应该可以只做response.data.item [0] .house_id或response ['data'] ['item'] [0] ['house_id'].
The __values__
attribute is a private implementation detail and you shouldn't really use it. You should be able to just do response.data.item[0].house_id or response['data']['item'][0]['house_id'].
请参见 https://github .com/mvantellingen/python-zeep/blob/master/src/zeep/xsd/valueobjects.py#L32 作为使用的代码.
See https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/xsd/valueobjects.py#L32 for the code used.
干杯,迈克尔(zeep的作者)
Cheers, Michael (author of zeep)
这篇关于python soap zeep模块获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!