Python xmltodict.parse returns 异常“格式不正确(无效标记):第 6 行,第 15 列

Python xmltodict.parse returns Exception "not well-formed (invalid token): line 6, column 15

使用以下代码片段我不确定如何解决错误 element/attribute。它似乎被正确引用并且采用正确的 utf-8 格式(我相信)。但是 \x07 绊倒了 xmltodict.parse

异常:格式不正确(无效标记):第 6 行,第 15 列

知道如何去除这些代码点以使其不抛出异常吗?

response = requests.get(dp_url, params=dp_params)

try:
    dict_response = xmltodict.parse(response.text)
except Exception as e:   ***not well-formed (invalid token): line 6, column 15***
    print(e)

XML:

<result><record><field name='donor_id' id='donor_id' value='40362'/><field name='first_name' id='first_name' value='John'/><field name='org_rec' id='org_rec' value='N'/><field name='donor_type' id='donor_type' value='IN'/><field name='nomail' id='nomail' value='N'/><field name='nomail_reason' id='nomail_reason' value=''/><field name='narrative' id='narrative' value='2/26/2021 - TD: added Louise to record. Check only has her name and didn&apos;t return the reply device.\r\n3/17/2015 - MS: Removed an extra sopace between Spring and St in Address field. \r\n\r\n8/26/2014 - MS: Moved initial to Middle Name field.\r\n\r\n11/14/2012 TD: \x07 telephone number added per telephone campaign 2012'/><field name='tag_date' id='tag_date' value=''/><field name='quickbooks_customer_id' id='quickbooks_customer_id' value=''/></record></result>

您是否尝试过只替换有问题的字符?

xmltodict.parse(response.text.replace('\x07', ''))