將圖片傳入接口中,並取得結果 ,話不多說,直接上代碼。
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)