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W0eZTi9M3hxruwoTqs4m+gQCFV7dD2hU+AgxjJcrkMsFLIqscC1Y0DI0kJ1/vdj3cQO6/3R2nRL9eVQZXJaBTt0zojWLZux8L3h2ODReofZt31Uq86PnLSRVZxWtQci3+t+m0vtdTdal+wQZjC0pMNeekiHqdSSrGoz3Re5FZ36zxa0kKX3tFzGzC98dBIyAjMmq8kqNZvEeV4aZ3m76M7Wiu3ufA8LiWWnIvI/gEEbrzvyUBsAAAAASUVORK5CYII=' def decode_base64(data): """Decode base64, padding being optional. :param data: Base64 data as an ASCII byte string :returns: The decoded byte string. """ missing_padding = len(data) % 4 if missing_padding != 0: data += b'='* (4 - missing_padding) # return base64.decodestring(data) return base64.b64decode(data) imgdata=decode_base64(strs) file=open('1.jpg','wb') file.write(imgdata) file.close()
#注意:你复制过来的字符串strs可能前缀带有红色标注的base64,你这时需要把他们给删了
然后运行,就可以搞定。
参考链接:http://blog.csdn.net/qzc295919009/article/details/42712801
http://bbs.csdn.net/topics/392045840