1

我做了一个小程序来测试微软认知服务,但它总是返回

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

我正在使用的代码是:

#!/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))

我做错了什么还是普遍的服务器问题?

4

1 回答 1

3

问题出在params变量中。在定义要提取的视觉特征时,您可以指定图像中的特定细节,如文档中所述。如果使用details字段,则必须使用可用的有效字符串选项之一进行初始化(目前,仅支持“Celebrities”选项,该选项将识别图像中的名人)。在这种情况下,您使用文档中注明的占位符('{string'})初始化详细信息字段。这导致系统出现内部错误。

要纠正这个问题,您应该尝试:

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

(PS:已经向微软认知服务报告了这种行为。)

于 2016-04-28T15:22:39.713 回答