Python base64 string to PyPng without saving file
问题 How do you do this without saving to disk and then opening 'out.png' ? r = requests.get(url) mine,encoded = r.json()[0]['data'].split(',') #if it is segmentation decoded = base64.decodestring(encoded) if mine == 'data:image/png;base64': #TODO do this from memory g = open("out.png", "w") g.write(decoded) g.close() r = png.Reader('out.png') print r.read() 回答1: Use the bytes keyword r = png.Reader(bytes=decoded) 回答2: base53.decodestring() returns a string of the binary data, and according to