Search code examples
pythonunicodeshapefile

UnicodeDecodeError 'utf-8' codec can't decode - using python shapefile reader


I'm trying to read a shapefile

r = shapefile.Reader(filepath, encoding = "utf-8")

but when I try to get a value from the .records() object like:

 r.records()[0]

it returns to me the following error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 4: invalid continuation byte

Solution

  • That means your file is not encoded in utf-8. Try: ISO8859-1

    If you are on Linux (or have git-bash on Windows) you can use the file command to find out the encoding.