"ASCII"编解码器无法解码位置 81 中的字节0xe2:序号不在范围内(128)



我正在尝试将以下 JSON 对象发送到 Web 服务 API 并遇到下面的错误 1,然后我.encode("utf-8").strip()添加到下面的标题(请参阅代码片段(然后运行到 Error1,现在不知道如何解决这个问题?有人提供指针吗?

{"component":{"name":"comp chip PCIe", "version":"X"},"assignee":123449612,"milestone":"Internal Tools - Mile","priority":2,"state":"Analyze","substate":"Nominate","title":"[Cloning for automation checkin]SVT:UDM:4364B2::SITM: Observing few instances of “CW Firmware Requested Dump PCIe~reason=(0x6)” followed by “watchdog@CW Chip Trap~Type=4,PC=0x1666F0,LR=0xEEEEEEEE” during SITM test."}

代码片段:

title = "[" + sys.argv[5] +"]" +  orgRadar['title'].encode("utf-8").strip()

错误 1:

'ascii' codec can't encode character u'u201c' in position 253: ordinal not in range(128)

错误 2:

'ascii' codec can't decode byte 0xe2 in position 81: ordinal not in range(128)

我认为你使用的是Python 2.x。您可以改用 3.x,您的代码无需编码即可正常工作。

对于 2.x,请参阅 Unicode HOWTO。简而言之,您可以将每个'your string'替换为 u'your string' .

相关内容

最新更新