python - AttributeError:“xml.etree.ElementTree.Element”对象没有属性“_children”
问题描述
我有以下代码:
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 中失败:
回溯(最后一次调用):文件“/Users/kaulk/sandbox/oktapod1/oktapod/helpers.py”,第 135 行,在假设角色原则_arns,role_arns = result_saml_decoded(resultsaml) 文件“/Users/kaulk/sandbox/oktapod1/ oktapod/helpers.py",第 188 行,在 result_saml_decoded inner_saml_tag = [saml2 for saml2 in root._children if 'Assertion' in saml2.tag] AttributeError: 'xml.etree.ElementTree.Element' 对象没有属性 '_children'
对于应该与 py27 和 36 兼容的代码,我应该使用什么?
解决方案
推荐阅读
- spring - 未注释的参数覆盖@??? 范围
- python - 通过匹配 Pandas df 中所有列中的子字符串来过滤所有行
- python - Pandas:在 groupby.apply 中将 group-key 作为参数提供给函数
- javascript - 如何解决语法错误:await 仅在异步函数中有效?
- angular-material - 我无法在 mat-from-field 中更改占位符颜色
- scroll - 如何使负值绝对定位元素滚动?
- simulink - 每次出现上升沿时如何从工作区读取\生成信号
- java - 使用 sendkeys 的 Selenium 上传不起作用 - 因为在上传之前有一个弹出窗口
- android - 使用导航组件时片段不显示
- javascript - 我想在 v-for 标记中设置一个自定义属性,如下面的代码,但是我怎样才能在 `computed` 方法中获得这个道具?