python 以body 内包含json 格式数据上传图片 视频

import requests
import os
import base64
import json
session = requests.session()

#url = "http://localhost:8080/sendData.do"
url = "http://58.210.249.27:9090/sendData.do"

image_path = "pic.jpg"
video_path="getVideo.webm"
data = {
"CameraID":"TV2",
"SysTime":"2020-05-25 17:00:00",
"MsgType":0,
"MsgID":1,
"MsgValue":2,
"Direction":"S2N",
"Snapshot":base64.b64encode(open(image_path,'rb').read()).decode(),
"Video":base64.b64encode(open(video_path,'rb').read()).decode()
}

session.headers = {
    'Host': 'ipadmin.zhaopingou.cn',
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0',
    'Accept': 'multipart/form-data',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    'Accept-Encoding': 'gzip, deflate',
    'Referer': 'http://qiye.zhaopingou.com/user/comProve',
    'Content-Length': '46192',
    'Content-Type': 'application/octet-stream',
    'Origin': 'http://qiye.zhaopingou.com',
    'Connection': 'keep-alive',
}

#image_path = os.path.join('/home/headhunter/Desktop/zhizhao',image_file)

res = session.post(url=url,data=json.dumps(data))
print('code:',res.status_code)
#print('content:',res.text)
 

你可能感兴趣的:(python 以body 内包含json 格式数据上传图片 视频)