Python UnicodeEncodeError : 'charmap' codec can't encode when using GEOPY

标签 python unicode encoding ffmpeg geolocation

我一直在摆弄 python geopy,并尝试了文档中给出的基本命令。但我得到了 UnicodeEncodeError 尝试 raw 时命令(将查询地理定位到地址和坐标)

print(location.raw)

错误 UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in position 83: character maps to <undefined>
然后我尝试了另一种方式(找到一组坐标对应的地址)
print(location.address)    

我遇到了同样的错误 UnicodeEncodeError: 'charmap' codec can't encode character '\u0101' in position 10: character maps to <undefined>
我试过print((location.address).encode("utf-8")) ,现在没有收到任何错误,但打印的输出是这样的 b'NH39, Mirz\xc4\x81pur
当使用 print((location.raw).encode("utf-8"))我收到错误
AttributeError: 'dict' object has no attribute 'encode'

谁能告诉我这里发生了什么以及我应该怎么做才能获得正确的输出?

编辑: (被标记为重复后)

Based on the solution given in this problem I am reporting on how it does not solve my problem

我想知道的是为什么我在尝试文档中给出的基本示例编码时会得到 UnicodeEncodeError 并且它确实回答了这个问题。

如果我想将它用作应用程序,我该如何解决错误,并且我不能让应用程序在单独的 IDE 上运行或将输出发送到外部文件,因为我的应用程序将根据 geopy 的输出运行,我希望应用程序运行在终端中,就像我的其他应用程序一样。

最佳答案

问题是您的控制台未设置为正确显示您尝试打印的 Unicode 字符。

在 Windows 7 中,对于 Python 3.3 + ,您可以将 python 控制台的代码页更改为 65001 以显示 unicode 字符。在终端运行以下 -

chcp 65001

在开始 python/你的脚本之前。

关于Python UnicodeEncodeError : 'charmap' codec can't encode when using GEOPY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31870452/

相关文章:

python - 导入错误 : No module named _mysql

python - numpy loadtxt、unicode 和 python 2 或 3

python unicode转换为日语字符

algorithm - 为什么 MQTT 对剩余长度使用如此奇怪的编码方案?

Java转换编码

python - Python 2.7 与 3.6 中 struct.unpack 的行为差异

python - 使用列表中的 startswith 的 Pyspark 过滤器

python - psycopg2.connect 失败,错误为 'connection refused'(Django app+db 托管在单独的虚拟机上)

python - 在 Python 中启用 Unicode "globally"

Java - 从混合了 UTF-8 和非 UTF-8 字符的字符串中准确计算 60 个字符