简体   繁体   English

UnicodeEncodeError:'ascii'编解码器无法编码字符u'\\ xe9'

[英]UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9'

I use python to get json data from bing api 我使用python从Bing API获取json数据

    accountKeyEnc = base64.b64encode(accountKey + ':' + accountKey)
    headers = {'Authorization': 'Basic ' + accountKeyEnc}
    req = urllib2.Request(bingUrl, headers = headers)
    response = urllib2.urlopen(req)
    content = response.read()
    data = json.loads(content)
    for i in range(0,6):
            print data["d"]["results"][i]["Description"]

But I got error 但是我有错误

print data["d"]["results"][0]["Description"] UnicodeEncodeError: 'ascii' codec can't encode character u'\\xe9' in position 11: ordinal not in range(128) 打印数据[“ d”] [“结果”] [0] [“描述”] UnicodeEncodeError:'ascii'编解码器无法在位置11编码字符u'\\ xe9':序数不在范围内(128)

Your problem is that you are reading Unicode from the Bing API and then failing to explicitly convert it to ASCII. 您的问题是您正在从Bing API中读取Unicode,然后无法将其显式转换为ASCII。 There does not exist a good mapping between the two. 两者之间没有良好的映射。 Prefix all of your const strings with u so that they will be seen as Unicode strings, see if that helps. u前缀所有const字符串,以便将它们视为Unicode字符串,看看是否有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UnicodeEncodeError:'ascii'编解码器不能编码字符u'\\ xe9' - UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' UnicodeEncodeError: 'ascii' codec can't encode character u'\\xe9' in position 54: ordinal not in range(128) - UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 54: ordinal not in range(128) 'ascii'编解码器无法编码字符u'\\ xe9' - 'ascii' codec can't encode character u'\xe9' Python eyed3 UnicodeEncodeError:'ascii'编解码器无法在位置17编码字符u'\\ xe9':序数不在范围内(128) - Python eyed3 UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 17: ordinal not in range(128) UnicodeEncodeError:'ascii'编解码器不能编码字符u'\\ xe4' - UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' UnicodeEncodeError: 'ascii' codec can't encode character '\\xe9' - -when using urlib.request python3 - UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' - -when using urlib.request python3 UnicodeEncodeError: 'ascii' 编解码器在 UTF-8 语言环境中打印时无法编码字符 '\\xe9' - UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' when printing in UTF-8 locale Python - 'ascii' 编解码器无法对位置 5 中的字符 u'\\xe9' 进行编码:序号不在范围内(128) - Python - 'ascii' codec can't encode character u'\xe9' in position 5: ordinal not in range(128) Cassandra:'ascii'编解码器无法在位置218处编码字符u'\\ xe9':序数不在范围内(128) - Cassandra : 'ascii' codec can't encode character u'\xe9' in position 218: ordinal not in range(128) UnicodeEncodeError:'ascii'编解码器无法在位置31编码字符'\\ xe9':安装金字塔期间序数不在range(128)中 - UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 31: ordinal not in range(128) during installing pyramid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM