根据post请求头的content-type不同而不同:
1. content-type为"application/x-www-form-urlencoded":
-
from urllib import parse
-
headers = {'content-type': 'application/x-www-form-urlencoded'}
-
url = "{0}".format(token)
-
with open(path, "rb") as video:
-
base64_video = base64.b64encode(video.read()).decode()
-
content = {'type': 'video','video_base64': base64_video}
-
data= parse.urlencode(content)
-
try:
-
response = requests.post(url=url,
-
data=data,
-
headers=headers,
-
)
-
res = response.json()
-
msg = res.get("error_msg")
-
xxx
-
except Exception as e:
-
xxx
2.
content-type为"application/json":
-
headers = {'content-type': 'application/json'}
-
url = "{0}".format(token)
-
with open(path, "rb") as video:
-
base64_video = base64.b64encode(video.read()).decode()
-
try:
-
response = requests.post(url=url,
-
data=json.dumps([{
-
"video": base64_video ,
-
"type": "BASE64",
-
}]),
-
headers=headers,
-
)
-
res = response.json()
-
msg = res.get("error_msg")
-
xxx
-
except Exception as e:
-
xxx
3.content-type为"form-data":
-
headers = {
-
"Cookie": "session_id=xxxxxx"
-
}
-
url = "{0}/df/upload".format(host)
-
content_type = "video/mp4"
-
#content_type = "image/jpg"
-
files = {
-
"file": (os.path.basename(file_path), open(file_path, "rb"), content_type),
-
}
-
data = {
-
"type": 1
-
}
-
if tid:
-
data["tid"] = tid
-
-
try:
-
response = requests.post(url, files=files, data=data, headers=headers)
-
res = response.json()
-
msg = res.get("error_msg")
-
xxx
-
except Exception as e:
-
xxx
阅读(3010) | 评论(0) | 转发(0) |