import requests
import json
import base64
import socket
# 首先將圖片讀入
# 由于要發(fā)送json,所以需要對byte進(jìn)行str解碼
def getByte(path):
with open(path, 'rb') as f:
img_byte = base64.b64encode(f.read())
img_str = img_byte.decode('ascii')
return img_str
img_str = getByte('./futi118.jpg')
url = 'http://10.168.1.155:1180/predict'
data = {'inputs':[{"b64":img_str}]}
# print(data["inputs"][0]["b64"])
json_mod = json.dumps(data)
res = requests.post(url=url, data=json_mod)
print(res.text)
# 如果服務(wù)器沒有報錯圃郊,傳回json格式數(shù)據(jù)
# print(eval(res.text))
參考