亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何對 html_string 進行 base64 編碼

如何對 html_string 進行 base64 編碼

楊__羊羊 2021-08-14 16:47:09
目的我正在嘗試將foliumchoropleth編碼為StringIO. 我基于我對相關查詢的回答。我已經在這里和這里檢查了答案。錯誤AttributeError: 'bytes' object has no attribute 'encode'代碼視圖.pydef 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}
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

經過一些反復試驗,以下對我有用:


解決方案

def get_choropleth(self, request):

        # make choropleth ('m')

        html_string = m.get_root().render()

        encoded_bytes = html_string.encode('utf-8')

        encoded_bytes = base64.b64encode(encoded_bytes)

        encoded_bytes = encoded_bytes.decode('utf8') # decode the b64 bytes for Unicode

        choropleth = encoded_bytes

        return {'choropleth':choropleth}


查看完整回答
反對 回復 2021-08-14
  • 1 回答
  • 0 關注
  • 321 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號