DecodeError:' utf8'编解码器无法在File" fiona \ ogrext.pyx"中解码

时间:2018-05-26 12:49:12

标签: python encoding geopandas fiona

当我尝试运行GeoPandas to_file时会弹出错误。错误消息是:

Traceback (most recent call last):
  File "<pyshell#88>", line 1, in <module>
    df.to_file('psuedo.shp')
  File "C:\Python27\ArcGIS10.5\lib\site-packages\geopandas\geodataframe.py", 
    line 365, in to_file
    to_file(self, filename, driver, schema, **kwargs)
  File "C:\Python27\ArcGIS10.5\lib\site-packages\geopandas\io\file.py", line 
    64, in to_file
    schema=schema, **kwargs) as colxn:
  File "C:\Python27\ArcGIS10.5\lib\site-packages\fiona\__init__.py", line 
    183, in open
    enabled_drivers=enabled_drivers, crs_wkt=crs_wkt)
  File "C:\Python27\ArcGIS10.5\lib\site-packages\fiona\collection.py", line 
    156, in __init__
    self.session.start(self, **kwargs)
  File "fiona\ogrext.pyx", line 948, in fiona.ogrext.WritingSession.start
DriverIOError: 'utf8' codec can't decode byte 0xb9 in position 41: invalid 
start byte

我已经检查过相关问题并了解到这种类型的错误通常是通过转换相关文件的编码来解决的。但我甚至找不到ogrext.pyx ......任何人都可以帮助我吗?我是python的新手,使用python2.7

1 个答案:

答案 0 :(得分:0)

在编写或阅读文件时尝试使用wbrb参数。

像这样:

with open("path to file", 'rb') as f:
  contents = f.read()