第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何對 html_string 進行 base64 編碼

如何對 html_string 進行 base64 編碼

楊__羊羊 2021-08-14 16:47:09
目的我正在嘗試將foliumchoropleth編碼為StringIO. 我基于我對相關(guān)查詢的回答。我已經(jīng)在這里和這里檢查了答案。錯誤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條經(jīng)驗 獲得超8個贊

經(jīng)過一些反復(fù)試驗,以下對我有用:


解決方案

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}


查看完整回答
反對 回復(fù) 2021-08-14
  • 1 回答
  • 0 關(guān)注
  • 320 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號