我正在尝试将以下JSON对象发送到webservice api并运行到下面的Error1,然后我将.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()
ERROR1:
'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)
答案 0 :(得分:0)
我认为您使用的是Python 2.x.您可以使用3.x代替,您的代码可以正常运行而无需编码。
对于2.x,请参阅Unicode HOWTO。简而言之,您可以使用'your string'
替换每个u'your string'
。