简体   繁体   English

Python - 为什么反向地理编码会引发 UnicodeDecode 错误?

[英]Python - Why is reverse geocode throwing a UnicodeDecode error?

I'm following the instructions at this link .我正在按照此链接中的说明进行操作。

The code is as follows:代码如下:

import reverse_geocode
coordinates = (-37.81, 144.96), (31.76, 35.21)
reverse_geocode.search(coordinates)

Instead of the output shown at the link, I get the following error:我收到以下错误,而不是链接中显示的输出:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 464: character maps to <undefined>

Note that it isn't an import problem;请注意,这不是导入问题; I could import the module fine with Python3.我可以用 Python3 很好地导入模块。

What's going wrong?怎么了?

This looks to be an issue with reverse_geocode .这看起来是reverse_geocode一个问题 This issue has been fixed in the source code as of July, but this fix has yet to make its way into a release.截至 7 月,此问题已在源代码中修复,但此修复程序尚未发布。

Until then, the workaround is to modify Lib\\site-packages\\reverse_geocode\\__init__.py under wherever you have Python installed.在此之前,解决方法是在安装 Python 的任何位置修改Lib\\site-packages\\reverse_geocode\\__init__.py Edit this file and add the argument encoding="utf-8" to all calls to open() .编辑此文件并将参数encoding="utf-8"到对open()所有调用。

修改 Lib\\site-packages\\reverse_geocode_ init _.py 并编辑 open(,encoding="utf-8")

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM