微软情感api视频python3中的错误消息

时间:2017-08-21 21:09:16

标签: python-3.x microsoft-cognitive

我试图通过视频获得情感

以下是我的代码,

总是在我运行此代码时出现此错误

b'{“error”:{“code”:“BadArgument”,“message”:“无法反序列化JSON请求。”}}'知道为什么?

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

headers = {

'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'xxxxxxxxxxx',
}

params = urllib.parse.urlencode({
})




body = "{ 'url': 'http://www.dropbox.com/s/zfmaswf8s9c58om/blog2.mp4' }"

try:

  conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
   conn.request("POST", "/emotion/v1.0/recognizeinvideo?%s" % params, "
  {body}", headers)
   response = conn.getresponse()
  data = response.read()
  print(data)
  conn.close()
except Exception as e:
  print(e.args)

1 个答案:

答案 0 :(得分:1)

您忘了用占位符{body}替换真实内容。

conn.request("POST", "/emotion/v1.0/recognizeinvideo?%s" % params, body, headers)