Python - 谷歌内容 API 和 unicode

标签 python unicode google-content-api

我搜索了很多页面来尝试帮助自己,现在我对 python2 和 unicode 比开始之前更加困惑。

我想要实现的目标:

使用适用于 Python 的 google content api v2,我编写了一个实现,该实现将从我们的数据库中获取产品并将其发布到 Google。

这工作正常,直到我得到一些含有 unicode 字符的产品。

从 google/python 返回的示例和错误是:

D' Addario EXP11 Coated Bronze Acoustic Guitar Strings, 12-53 
Fender Stop Dreaming, Start Playing™ Affinity P Bass® With Rumble™ 15 

ERROR'utf8' codec can't decode byte 0x92 in position 1: invalid start byte
ERROR'utf8' codec can't decode byte 0x99 in position 35: invalid start byte

我知道它的 ' ® ™ 字符,但我无法计算出它的 .encode/.decode 等方面。

那么,谁能告诉我如何获取这些带有特殊字符的产品名称,以便将它们发布到 Google?

==更新== 我从 MySQL 数据库获取产品名称。该表设置为使用 UTF-8 作为编码。

最佳答案

尝试:

u'Addario EXP11 Coated Bronze Acoustic Guitar Strings, 12-53 
Fender Stop Dreaming, Start Playing™ Affinity P Bass® With Rumble™ 15'

unicode('Addario EXP11 Coated Bronze Acoustic Guitar Strings, 12-53 
Fender Stop Dreaming, Start Playing™ Affinity P Bass® With Rumble™ 15')

但除此之外。很多时候,Python 2 中的 Unicode 支持是一件令人头疼的事情。我建议尝试使用 unicode 为标准的 Python 3。

关于Python - 谷歌内容 API 和 unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30666399/

相关文章:

python - 存在哪些模板系统适合编写服务创建配方

python - 三字母词广度优先搜索,优化

python - 使用 Python 从字符串中删除度数符号

javascript - Rhino 中的 Unicode

javascript - 不带 HTTPS 的 Google 通讯录 API

python - 导入错误 : No module named 'tweepy.streaming' ; 'tweepy' is not a package

vb.net - .NET本地化: Japanese Characters Display as Squares

c# - 使用 p12 key 进行身份验证时出现错误 用户无法访问帐户

python - 通过Python访问Google Shopping API

python - 如何将一个简单的 "colorbar"添加到 python 中的网络图?