我正在尝试编写xml规范化usign python 3.6的方法
现在我有此功能,可以接收xml作为以base64编码的参数,因此我必须对其进行解码才能使用它
def canonicalize(xml, c14n_exc=True):
"Return the canonical (c14n) form of the xml document for hashing"
# UTF8, normalization of line feeds/spaces, quoting, attribute ordering...
xml_decoder = base64.b64decode(xml).decode("utf-8")
output = StringIO()
if xml_decoder is not None:
# use faster libxml2 / lxml canonicalization function if available
et = lxml.etree.parse(StringIO(xml_decoder))
et.write_c14n(output, exclusive=c14n_exc)
#else:
# use pure-python implementation: c14n.py (avoid recursive import)
#from .simplexml import SimpleXMLElement
#SimpleXMLElement(xml).write_c14n(output, exclusive=c14n_exc)
return output.getvalue()
问题是我收到以下错误 valueError ::“字符串参数预期,得到了'字节'” 。
知道我在做什么错吗?
谢谢