Alex Torres
Alex Torres

Reputation: 11

error message in microsoft emotion api video python3

Im trying to get the emotions from a video

Below is my code,

Always when I run this code i get this error

b'{"error":{"code":"BadArgument","message":"Failed to deserialize JSON request."}}' any idea why?

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)

Upvotes: 1

Views: 73

Answers (1)

cthrash
cthrash

Reputation: 2973

You forgot to substitute the placeholder {body} with the real thing.

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

Upvotes: 1

Related Questions