python 将图片Base64编码转换成二进制并保存本地

import json
from base64 import b64decode

response = {"result":0,"system":{"redirect":0,"uid":"","controller":"otherAuthService","trace_id":"AC1000F715911718971352421047CF","token_id":"","time_stamp":1591171897,"need_login":0,"action":"getImageCode","session_id":"0edc4984c34543d09adef33f9cb4c745","new_version":"3.1.0","auth_status":0,"email":""},"data":{"result":0,"result_rows":{"session_id":"0edc4984c34543d09adef33f9cb4c745","image_code_base64":"/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a\nHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy\nMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAgAFoDASIA\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+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REZADnnChl5x6tjp05zYlS4Aby5CwJzjgMv0OMfgR+NVb\nrUbfSvIa9ubj9+3lxqYd+XPQfIvX0HfnGaw57P3l/X3mdufTVGV5GtzSYF3arfp88p8ho0lUfwDE\njGMn5fmy+OTtPQXI4rgWN3YDZb3ssLbHWQkKxXAw2ATg98evAp6y/ariaSyuDBcuoCC7s5FHbOFY\noW4B6HjIz72/sk8ttF9qnja6jOfNiiKL1/ulm7Y79vwrxKeAnDmxEI++pye+8W9uyutV57g1pysg\n0lVddRVlDK15ICCMgjiqEjnS0vtOl+W3like2diccj7g6/5+orTsLCewd1WZJYJJGdgysHUnvuJO\n7oBzzznPY4upa3pWpRNbzLLbTKcxm6CQPjP3gkjKxU9M4x+Ir6iFROeqdmNSvuivpfhS9sLVH0XX\nprGG4RZJIZIFmAcjqucYGMD145J7ZZ8Pwaj8Q7m0YXFzbxWjrqMtwxzKZUZcArgD5XUADbgIcdOb\ny+CdUIDQeKdUtUIH7qRizDAA6rJjtx6DArfs/DVpY6Ve2VtPdJLeK4mvRJ/pBZgRuD44YZyOODz1\nJzzuzd1oei8Qoxb5+ZtW2tv3fX8Tl9L+HWs6A0Vpovje+tdGim81bSS0ilcAjDgSHjByxA24BOcE\n8nmPhvoF5D8SPE19YTk2tmDp8lzdxOzXE+5TI33zklo2Ynd/GvyjOBvX3hjxl5bWf/CZaudNR1Ub\nbSJZjErDA8+NjJuIH3thyeSME10nhmy0zw/oEGlaLZNbOMkQ32YpJ3/idm2nc2BngHAwOBgDoniF\nySi5Xcuyt+NlqcEcRF3jfX0/zOjhEqxATOjyd2RCoP4En+dPrGXXreXV20K4ZrHUng8yMGSM7wdw\nzFkkvjY5+7wFywGQCv8AZOqf9DHef+A8H/xFci20Bn//2Q=="},"res_info":"ok"},"res_info":"ok"}
=======================================
file_path='D:\\img\\'
response_parsed = json.loads(response)
img = response['data']['result_rows']['image_code_base64']
temp = base64.b64decode(img)
with open(file_path + "a.jpg", "wb") as fp:
    fp.write(temp)

你可能感兴趣的:(python 将图片Base64编码转换成二进制并保存本地)