【发布时间】:2019-04-14 03:50:26
【问题描述】:
目标
我正在尝试将folium choropleth 编码为StringIO。我的回答基于related query。我已经检查了here 和here 的答案。
错误
AttributeError: 'bytes' object has no attribute 'encode'
代码
views.py
def get_choropleth(self, request):
# make choropleth ('m')
html_string = m.get_root().render()
f = StringIO(html_string)
choropleth = base64.b64decode(f.read())
choropleth = choropleth.encode('utf8') # causing error
return {'choropleth':choropleth}
【问题讨论】:
-
只需尝试将
choropleth.encode('utf8')替换为choropleth.decode('utf8'),请参考documentation -
好吧
b'\xe0'.decode('latin')将输出'à'。所以,也许您的字符串并不真正符合utf8标准。
标签: python django base64 stringio