简体   繁体   English

Python UnicodeEncodeError:使用 GEOPY 时无法编码“charmap”编解码器

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

I have been fiddling with python geopy and I tried the basic commands given in the documentation.我一直在摆弄 python geopy,并尝试了文档中给出的基本命令。 But I am getting the UnicodeEncodeError when trying the raw command(to geolocate a query to an address and coordinates)但是我在尝试raw命令时收到UnicodeEncodeError (将查询地理定位到地址和坐标)

print(location.raw)

Error UnicodeEncodeError: 'charmap' codec can't encode character '\\xa9' in position 83: character maps to <undefined>错误UnicodeEncodeError: 'charmap' codec can't encode character '\\xa9' in position 83: character maps to <undefined>

Then I tried the other way around (To find the address corresponding to a set of coordinates)然后我尝试了另一种方式(找到一组坐标对应的地址)

print(location.address)    

I am getting the same error UnicodeEncodeError: 'charmap' codec can't encode character '\ā' in position 10: character maps to <undefined>我收到同样的错误UnicodeEncodeError: 'charmap' codec can't encode character '\ā' in position 10: character maps to <undefined>

I tried print((location.address).encode("utf-8")) , now am not getting any error but the output printed is like this b'NH39, Mirz\\xc4\\x81pur我试过print((location.address).encode("utf-8")) ,现在没有得到任何错误,但打印的输出是这样的b'NH39, Mirz\\xc4\\x81pur

and when using print((location.raw).encode("utf-8")) I am getting error当使用print((location.raw).encode("utf-8"))我收到错误

AttributeError: 'dict' object has no attribute 'encode'

Can anyone tell me what is going on here and what I should do to get a proper output?谁能告诉我这里发生了什么以及我应该怎么做才能获得正确的输出?

Edit: (After being marked as duplicate)编辑:(被标记为重复后)

Based on the solution given in this problem I am reporting on how it does not solve my problem基于此问题中给出的解决方案,我正在报告它如何无法解决我的问题

What I wanted to know is why do I get the UnicodeEncodeError when trying out the basic sample codings given in the documentation and it did answer for that.我想知道的是为什么我在尝试文档中给出的基本示例编码时会得到 UnicodeEncodeError 并且它确实回答了这个问题。

If I want to use it an application how do I solve the error and I cannot have the application running on separate IDE or send the output to a external file since my application will function based on the output from geopy, I want the application to run in the terminal as my other applications do.如果我想将它用作应用程序,我该如何解决错误并且我不能让应用程序在单独的 IDE 上运行或将输出发送到外部文件,因为我的应用程序将根据 geopy 的输出运行,我希望应用程序运行在终端中,就像我的其他应用程序一样。

The issue is that your console is not setup to correctly show the unicode characters that you are trying to print.问题是您的控制台未设置为正确显示您尝试打印的 unicode 字符。

In Windows 7, for Python 3.3 + , you can change the code page of python console to 65001 for it to show unicode characters.在 Windows 7 中,对于 Python 3.3 + ,您可以将 python 控制台的代码页更改为 65001 以显示 unicode 字符。 In terminal run the following -在终端运行以下 -

chcp 65001

Before starting python/your script.在开始 python/你的脚本之前。

print json.dumps(address_object.raw,ensure_ascii=False, encoding="utf-8").encode('utf-8')

请检查,希望这对你有用

暂无
暂无

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

相关问题 Python Selenuim - UnicodeEncodeError 'charmap' 编解码器无法编码 - Python Selenuim - UnicodeEncodeError 'charmap' codec can't encode Python,UnicodeEncodeError:“ charmap”编解码器无法在位置编码字符 - Python, UnicodeEncodeError: 'charmap' codec can't encode characters in position MongoDB中的Python错误“ UnicodeEncodeError:&#39;charmap&#39;编解码器无法编码字符” - Python error “UnicodeEncodeError: 'charmap' codec can't encode character” in MongoDB Python Dataframe 到 CSV - UnicodeEncodeError: 'charmap' 编解码器无法编码字符 - Python Dataframe to CSV - UnicodeEncodeError: 'charmap' codec can't encode characters UnicodeEncodeError:&#39;charmap&#39;编解码器无法编码字符 - UnicodeEncodeError: 'charmap' codec can't encode character UnicodeEncodeError: 'charmap' 编解码器无法编码字符 - UnicodeEncodeError: 'charmap' codec can't encode characters 使用 Webscraper 写入 csv 时出现“UnicodeEncodeError: &#39;charmap&#39; codec can&#39;t encode character” - “UnicodeEncodeError: 'charmap' codec can't encode character” When Writing to csv Using a Webscraper Python 3-UnicodeEncodeError:“ charmap”编解码器无法编码字符(编码后在文件中) - python 3 - UnicodeEncodeError: 'charmap' codec can't encode character (Encode so it's in a file) UnicodeEncodeError: &#39;charmap&#39; 编解码器无法编码字符:字符映射到<undefined> - UnicodeEncodeError: 'charmap' codec can't encode character : character maps to <undefined> Pandas UnicodeEncodeError: &#39;charmap&#39; 编解码器无法编码字符 - Pandas UnicodeEncodeError: 'charmap' codec can't encode character
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM