我有以下代码:
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中失败,原因是:
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'
对于应该与py27和36兼容的代码,我应该使用什么?在
目前没有回答
相关问题 更多 >
编程相关推荐