zoukankan      html  css  js  c++  java
  • 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
    HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
    MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAgAFoDASIA
    AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
    AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3
    ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm
    p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA
    AwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx
    BhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK
    U1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3
    uLm6wsPExcbHyMnK0tPU1db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GfrjGPfpVbUk1YgnTJrWM7Rn7REZADnnChl5x6tjp05zYlS4Aby5CwJzjgMv0OMfgR+NVb
    rUbfSvIa9ubj9+3lxqYd+XPQfIvX0HfnGaw57P3l/X3mdufTVGV5GtzSYF3arfp88p8ho0lUfwDE
    jGMn5fmy+OTtPQXI4rgWN3YDZb3ssLbHWQkKxXAw2ATg98evAp6y/ariaSyuDBcuoCC7s5FHbOFY
    oW4B6HjIz72/sk8ttF9qnja6jOfNiiKL1/ulm7Y79vwrxKeAnDmxEI++pye+8W9uyutV57g1pysg
    0lVddRVlDK15ICCMgjiqEjnS0vtOl+W3like2diccj7g6/5+orTsLCewd1WZJYJJGdgysHUnvuJO
    7oBzzznPY4upa3pWpRNbzLLbTKcxm6CQPjP3gkjKxU9M4x+Ir6iFROeqdmNSvuivpfhS9sLVH0XX
    prGG4RZJIZIFmAcjqucYGMD145J7ZZ8Pwaj8Q7m0YXFzbxWjrqMtwxzKZUZcArgD5XUADbgIcdOb
    y+CdUIDQeKdUtUIH7qRizDAA6rJjtx6DArfs/DVpY6Ve2VtPdJLeK4mvRJ/pBZgRuD44YZyOODz1
    Jzzuzd1oei8Qoxb5+ZtW2tv3fX8Tl9L+HWs6A0Vpovje+tdGim81bSS0ilcAjDgSHjByxA24BOcE
    8nmPhvoF5D8SPE19YTk2tmDp8lzdxOzXE+5TI33zklo2Ynd/GvyjOBvX3hjxl5bWf/CZaudNR1Ub
    bSJZjErDA8+NjJuIH3thyeSME10nhmy0zw/oEGlaLZNbOMkQ32YpJ3/idm2nc2BngHAwOBgDoniF
    ySi5Xcuyt+NlqcEcRF3jfX0/zOjhEqxATOjyd2RCoP4En+dPrGXXreXV20K4ZrHUng8yMGSM7wdw
    zFkkvjY5+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)
    
  • 相关阅读:
    英雄大乱斗
    深浅拷贝(copy)
    myleecode
    代码量简单统计
    pandas 模块 05
    matplotlib 模块 07
    KVC 和KVO浅谈
    iOS开发中懒加载的使用和限制
    关于空白模板插件的使用
    UIImageC处理
  • 原文地址:https://www.cnblogs.com/gqv2009/p/13040011.html
Copyright © 2011-2022 走看看