【问题标题】:Getting wrong Unicode from Habenero API in Python从 Python 中的 Habenero API 获取错误的 Unicode
【发布时间】:2018-05-22 22:48:43
【问题描述】:

我正在调用Habanero API,它是CrossRef 的前端。使用此代码:

import json
from habanero import cn

x = cn.content_negotiation(ids="10.1051/0004-6361/201628812",
    format = "text", style = 'elsevier-harvard')

print(u'{0}'.format(x))
print(json.dumps(x, indent=4, sort_keys=True))

我得到以下输出(强调我的):

Hawkins, K.、Masseron, T.、Jofré, P.、Gilmore, G.、Elsworth, Y.、Hekker, S.,2016 年。一种准确且自洽的化学品APOGEE/Keplersample 的丰度目录。天文学与天体物理学 594,A43。

"Hawkins, K., Masseron, T., Jofr\u00c3\u00a9, P., Gilmore, G., Elsworth, Y., Hekker, S., 2016 年。 APOGEE/Keplersample 的自洽化学丰度目录。Astronomy & Astrophysics 594, A43。\n"

第三位作者的名字应该是Jofré,所以我想最后一个字符应该是\uc3a9。从 JSON 转储看来,它正在发送 \u00c3\u00a9 。我在请求或解码时做错了吗?

【问题讨论】:

  • 是的,解码出了点问题:“é”的 UTF-8 表示,即字节序列 C3 A9,被解释为 Latin-1,导致“é” .这在 JSON 输出中清楚地显示,应该是“\u00e9”。我怀疑这是 habanero 的错,在他们的 GitHub 存储库上提交问题是正确的做法。

标签: python unicode habanero


【解决方案1】:

git repo 中修复。 h/t @sckott。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-06
    • 2019-08-17
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多