Python Base64编码

Base64编码html

  • base64.b64encode(s[altchars])python

  • base64.urlsafe_b64encode(s)json

  This allows an application to e.g. generate URL or filesystem safe Base64 strings数据结构

因为标准的Base64编码后可能出现字符+/ 而在URL中就不能直接做为参数app

因此"url safe"的urlsafe_b64encode编码,就把字符+/分别变成-编码

base64.b64encode('i\xb7\x1d\xfb\xef\xff')
'abcd++//'
base64.urlsafe_b64encode('i\xb7\x1d\xfb\xef\xff')
'abcd--__'

因为=字符也可能出如今Base64编码中,但=用在URL、Cookie里面会形成歧义,所以,不少Base64编码后会把=去掉url

python 3中转码的方式spa

base64.urlsafe_b64encode(bytes(‘str’, "utf-8")  code


今天碰到的一个问题:htm

    如何对一个数据结构 进行base64编码?

        方法: json.dumps()    把一种数据结构转成 字符串类型。

        而后再对使用 base64.编码

相关文章
相关标签/搜索