首页 > 解决方案 > 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

标签: pythonunicodeshapefile

解决方案


这意味着您的文件未以 utf-8 编码。尝试:ISO8859-1

如果您在 Linux 上(或在 Windows 上使用 git-bash),您可以使用该file命令找出编码。


推荐阅读