在逗号上分割数据URI,以获得没有标题的base64编码数据。调用
base64.b64depre以将其解码为字节。最后,将字节写入文件。
from base64 import b64depredata_uri = "data:image/png;base64,iVBORw0KGg..."# Python 2 and <Python 3.4header, enpred = data_uri.split(",", 1)data = b64depre(enpred)# Python 3.4+# from urllib import request# with request.urlopen(data_uri) as response:# data = response.read()with open("image.png", "wb") as f: f.write(data)


