UnicodeDecodeError:“ ascii”编解码器无法解码位置10894的字节0xe2:序号不在range(128)

时间:2018-12-11 23:31:52

标签: python-3.x pyspark shapely folium fiona

我正在关注此示例(https://github.com/geodocker/geodocker-jupyter-geopyspark/blob/master/notebooks/sanfranmvp.ipynb),所以我可以复制类似的输出,除最后一个外,每个都成功,我尝试了所有可能的调整,但没有成功,请有人可以帮助告诉我我做错了什么。这是使用folium在Jupyter笔记本中查看我的地图的代码的最后一步。

m = folium.Map(tiles='OpenStreetMap', location=map_center, zoom_start=zoom)

folium.TileLayer(tiles=tms.url_pattern, attr='GeoPySpark', name='Weighted layer', overlay=True).add_to(m)

folium.GeoJson('data/bars.geojson', name='Bars', style_function=lambda x: {'radius': 2, 'color': 'red'}, overlay=True).add_to(m)

folium.GeoJson('data/cafes.geojson', name='Cafes', style_function=lambda x: {'fillColor': 'orange'}, overlay=True).add_to(m)

folium.GeoJson('data/transit.geojson', name='Transit', style_function=lambda x: {'fillColor': 'green'}, overlay=True).add_to(m)

m

这是错误消息:

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-13-42944e2ceb84> in <module>()
     11 m = folium.Map(tiles='OpenStreetMap', location=map_center, zoom_start=zoom)
     12 folium.TileLayer(tiles=tms.url_pattern, attr='GeoPySpark', name='Weighted layer', overlay=True).add_to(m)
---> 13 folium.GeoJson('data/bars.geojson', name='Bars', style_function=lambda x: {'radius': 2, 'color': 'red'}, overlay=True).add_to(m)
     14 folium.GeoJson('data/cafes.geojson', name='Cafes', style_function=lambda x: {'fillColor': 'orange'}, overlay=True).add_to(m)
     15 folium.GeoJson('data/transit.geojson', name='Transit', style_function=lambda x: {'fillColor': 'green'}, overlay=True).add_to(m)


/usr/local/lib/python3.4/site-packages/folium/features.py in __init__(self, data, style_function, name, overlay, control, smooth_factor, highlight_function)
    480             else:  # This is a filename
    481                 with open(data) as f:
--> 482                     self.data = json.loads(f.read())
    483         elif data.__class__.__name__ in ['GeoDataFrame', 'GeoSeries']:
    484             self.embed = True


/usr/lib64/python3.4/encodings/ascii.py in decode(self, input, final)
     24 class IncrementalDecoder(codecs.IncrementalDecoder):
     25     def decode(self, input, final=False):
---> 26         return codecs.ascii_decode(input, self.errors)[0]
     27 
     28 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 10894: ordinal not in range(128)

1 个答案:

答案 0 :(得分:0)

这是我对此问题的最终解决方案,在@ottomeister的帮助下,我能够缩小研究范围,从而找到了解决方案。

m = folium.Map(tiles='OpenStreetMap', location=map_center, zoom_start=zoom)
folium.TileLayer(tiles=tms.url_pattern, attr='MYGeoPySpark', name='Weighted layer', overlay=True).add_to(m)
folium.GeoJson(json.load(open('data/bars.geojson', encoding = 'utf-8')), name='Bars', style_function=lambda x: {'radius': 2, 'color': 'red'}, overlay=True).add_to(m)
folium.GeoJson(json.load(open('data/cafes.geojson', encoding = 'utf-8')), name='Cafes', style_function=lambda x: {'fillColor': 'orange'}, overlay=True).add_to(m)
folium.GeoJson(json.load(open('data/transit.geojson', encoding = 'utf-8')), name='Transit', style_function=lambda x: {'fillColor': 'green'}, overlay=True).add_to(m)

m