[英]UnicodeEncodeError: 'charmap' codec can't encode character
Python throws this when using the wolfram alpha api: 使用wolfram alpha api时,Python会抛出这个:
Traceback (most recent call last):
File "c:\Python27\lib\threading.py", line 530, in __bootstrap_inner
self.run()
File "c:\Python27\lib\site-packages\Skype4Py\utils.py", line 225, in run
handler(*self.args, **self.kwargs)
File "s.py", line 38, in OnMessageStatus
if body[0:5] == '!math':wolfram(body[5:], '')
File "s.py", line 18, in wolfram
print "l: "+l
File "c:\Python27\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xd7' in position 3
: character maps to <undefined>
how can I solve this? 我该怎么解决这个问题?
Looks like you're passing in high-byte data to the API, and it's not liking that (\\xd7 is the "Times" character; looks like an X). 看起来你正在将高字节数据传递给API,并且它不喜欢(\\ xd7是“Times”字符;看起来像X)。 I'm not certain what purpose the print is for, but changing it to be print "l: " + repr(l)
or print "l: ", l
might at least get you past the above error, assuming you don't want to be in the business of converting the body to unicode (I'm assuming it's not...). 我不确定打印的目的是什么,但将其更改为print "l: " + repr(l)
或print "l: ", l
可能至少会让您超过上述错误,假设您没有我希望从事身体转换为unicode(我假设它不是......)。
If that doesn't help, we'll need more details. 如果这没有帮助,我们需要更多细节。 Where is your input coming from? 你的意见来自哪里? Is body unicode, or a byte string? 是身体unicode,还是字节串? Are you using python 2.7 or 3.x? 你在使用python 2.7或3.x吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.