AttributeError:“ xml.etree.ElementTree.Element”对象没有属性“ _children”

时间:2018-06-26 17:38:04

标签: python python-3.x python-2.7

我有以下代码:

def result_saml_decoded(result_saml):
"""Illustrate to result saml decoded value as response in a string.

:param result_saml:results saml decoded
:return:return principle_arn, resultsamldecoded, role_arns

"""
result_saml_decoded = base64.b64decode(result_saml)
root = ET.fromstring(result_saml_decoded)
principle_arns, role_arns = [], []
inner_saml_tag = [saml2 for saml2 in root._children if 'Assertion' in saml2.tag]
attribute_saml_tag = [saml_tag for saml_tag in inner_saml_tag[0]._children
                      if 'AttributeStatement' in saml_tag.tag]
for inner_saml_tag in attribute_saml_tag[0]._children:
    if 'uri' in inner_saml_tag.get('NameFormat'):
            for saml_data in inner_saml_tag._children:
                parts = saml_data.text.split(',')
                principle_arns.append(parts[0])
                role_arns.append(parts[1])

return principle_arns, role_arns

在python 2.7中有效,但在python 3.6中失败:

  

回溯(最近通话最近):        在第135行中输入“ /Users/kaulk/sandbox/oktapod1/oktapod/helpers.py”文件        假设角色        Principle_arns,Role_arns = result_saml_decoded(resultsaml)        文件“ /Users/kaulk/sandbox/oktapod1/oktapod/helpers.py”,第188行,位于        result_saml_decoded         inner_saml_tag = [saml2表示root中的saml2。_children,如果在'Assertion'中        saml2.tag]        AttributeError:“ xml.etree.ElementTree.Element”对象没有属性        '_children'

对于应该与py27和36兼容的代码,我应该使用什么?

0 个答案:

没有答案