python - UnicodeDecodeError 'utf-8' codec can't decode - using python shapefile reader
问题描述
我正在尝试读取 shapefile
r = shapefile.Reader(filepath, encoding = "utf-8")
但是当我尝试从.records()对象中获取值时,例如:
r.records()[0]
它返回给我以下错误:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 4: invalid continuation byte
解决方案
这意味着您的文件未以 utf-8 编码。尝试:ISO8859-1
如果您在 Linux 上(或在 Windows 上使用 git-bash),您可以使用该file
命令找出编码。
推荐阅读
- android - 图像的实时捕获未提供任何结果(ml kit Vision)
- excel - 缺失值替换为下一个可用的值,保留列标题
- c# - 如何使用 C# 中的扩展方法获取嵌套字典?
- javascript - Shiny and rhandsontable - 基于列总和的条件单元格/列格式
- java - 存储库到服务的依赖关系不满足
- python - JSON 中的 Python If 语句
- reactjs - React 中的条件路由
- groovy - 如何在使用 Groovy 附加两个数据集时添加具有某个常数值的新列?
- tomcat - 在端口 8080 OS X 上启动 tomcat 时出现错误 502 Bad Gateway
- android - locationListener 在前台服务 30 秒后不起作用