我们模拟一个发送数据的端口
import requests
import json
import cv2
url = 'http://10.11.24.23:3344/getimg'
img = cv2.imread('reading2/1.jpg')
_,img_encoded = cv2.imencode('.jpg', img)#.jpg 编码格式 将图像进行编码
# data = {
# 'key': 'emotion',
# 'data': 'img'
# }
## headers中添加content-type参数,指定为json格式
headers = {'Content-Type': 'application/json'}
## post时,用json包将data字典形式的参数转换成json格式。
response = requests.post(url= url, headers=headers, data=img_encoded.tobytes())