【问题标题】:How to upload a video file using python in video indexer api?如何在视频索引器 api 中使用 python 上传视频文件?
【发布时间】:2018-04-21 22:00:55
【问题描述】:

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

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} 部分指定如何提供视频文件。

请帮助我。

【问题讨论】:

  • 请花点时间让您的代码清晰易读。这个问题目前的表现是不可接受的。

标签: python-3.x microsoft-cognitive azure-cognitive-services video-indexer


【解决方案1】:

这对我有用:

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))

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 2016-01-12
    • 1970-01-01
    • 2011-09-20
    • 2019-11-22
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2020-06-27
    相关资源
    最近更新 更多