AttributeError: 'xml.etree.ElementTree.Element' object has no attribute '_children'

佐手、 提交于 2021-01-28 01:35:40

问题


I have the following code :

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

which works in python 2.7 but fails in python 3.6 with :

Traceback (most recent call last): File "/Users/kaulk/sandbox/oktapod1/oktapod/helpers.py", line 135, in assume_role principle_arns, role_arns = result_saml_decoded(resultsaml) File "/Users/kaulk/sandbox/oktapod1/oktapod/helpers.py", line 188, in result_saml_decoded inner_saml_tag = [saml2 for saml2 in root._children if 'Assertion' in saml2.tag] AttributeError: 'xml.etree.ElementTree.Element' object has no attribute '_children'

what am I supposed to use for code that is supposed to be compatible with py27 and 36 ?

来源:https://stackoverflow.com/questions/51048678/attributeerror-xml-etree-elementtree-element-object-has-no-attribute-childr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!