如何在视频索引器 api 中使用 python 上传视频文件? [英] How to upload a video file using python in video indexer api?

查看:89
本文介绍了如何在视频索引器 api 中使用 python 上传视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Python 在 Video Indexer API 中上传视频:

I am trying to upload a video in Video Indexer API using Python:

import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'multipart/form-data',
    'Ocp-Apim-Subscription-Key': '******************',
}

params = urllib.parse.urlencode({
    # Request parameters
    'name': 'xxxx',
    'privacy': 'Private',
    'language': 'English',

})

try:
    conn = http.client.HTTPSConnection('videobreakdown.azure-api.net')
    conn.request("POST", "/Breakdowns/Api/Partner/Breakdowns?%s" % params, "{body}", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

但我无法在 {body} 部分指定如何提供视频文件.

But I am not able to specify how to give the video file in the {body} section.

请帮助我.

推荐答案

这对我有用:

import requests
import urllib.parse
import json

headers = {
    'Ocp-Apim-Subscription-Key': 'YOUR-API-KEY',
}

form_data = {'file': open('YOUR-VIDEO.mp4', 'rb')}

params = urllib.parse.urlencode({
    'name': 'video.mp4',
    'privacy': 'Private',
    'language': 'English',
})

try:
    url = 'https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns?'
    r = requests.post(url, params=params, files=form_data, headers=headers)
    print(r.url)
    print(json.dumps(r.json(), indent=2))
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

这篇关于如何在视频索引器 api 中使用 python 上传视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆