ppaulojr
ppaulojr

Reputation: 3647

Microsoft Cognitive Service Internal Server Error for /vision/v1.0/analyze

I made a small program to test Microsoft Cognitive Service, but it always return

{
 "code":"InternalServerError",
 "requestId":"6d6dd4ec-9840-4db3-9849-a6497094fa4c",
 "message":"Internal server error."
}

The code I'm using is:

#!/usr/bin/env python
import httplib, urllib, base64

headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '53403359628e420ab85a516a79ba1bd0',
}

params = urllib.urlencode({
    # Request parameters
    'visualFeatures': 'Categories,Tags,Adult,Description,Faces',
    'details': '{string}',
})

try:
    conn = httplib.HTTPSConnection('api.projectoxford.ai')

    conn.request("POST", "/vision/v1.0/analyze?%s" % params, 
       '{"url":"http://static5.netshoes.net/Produtos/bola-umbro-neo-liga-futsal/28/D21-0232-028/D21-0232-028_zoom1.jpg?resize=54g:*"}', headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

Am I doing something wrong or it's a generalized server problem?

Upvotes: 1

Views: 338

Answers (1)

Cristian Canton
Cristian Canton

Reputation: 196

The problem is in the params variable. When defining which visual features you would like to extract you can specify specific details from the image, as described in the documentation. The details field, if used, must be initialized with one of the valid string options available (currently, only supporting the "Celebrities" option, that would identify which celebrity is in the image). In this case, you initialized the details field with literally the placeholder noted in the documentation ('{string'}). That caused the system to give an internal error.

To correct that, you should try:

params = urllib.urlencode({
    # Request parameters
   'visualFeatures': 'Categories,Tags,Adult,Description,Faces',
   'details': 'Celebrities',
})

(PS: Have already reported this behavior to Microsoft Cognitive Services.)

Upvotes: 3

Related Questions