將圖片解讀爲base64編碼並傳到接口中

將圖片傳入接口中,並取得結果 ,話不多說,直接上代碼。

import base64
import requests

def img_to_base64(img_path):   #將圖片轉爲base64編碼格式
    with open(img_path,'rb') as f:
        img_base64=base64.b64decode(f.read())
        return img_base64

def post(img_path):   #將base64格式傳入接口中,進行響應
    url=""
    data={"img":img_to_base64(img_path)}
    req=requests.post(url,data=data)
    response=req.next
    print response

if __name__ == '__main__':
    img_path=""
    post(img_path)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章