0

我在运行时遇到了微软用于人脸识别的视觉认知 api 的问题python create_person.py user52

Traceback (most recent call last):
  File "create_person.py", line 9, in <module>
    res = CF.person.create(personGroupId, str(sys.argv[1]))
  File ".../cognitive_face/person.py", line 74, in create
    return util.request('POST', url, json=json)
  File ".../cognitive_face/util.py", line 106, in request
    response.status_code, response.text)
cognitive_face.util.CognitiveFaceException: Error when calling Cognitive Face API:
    status_code: 404
    code: 404
    message: { "statusCode": 404, "message": "Resource not found" }

这是我的 create_person.py 文件

import sys
import cognitive_face as CF
from global_variables import personGroupId
import sqlite3

Key = 'b065632b79ac4d97a96d5781463d54b1'
CF.Key.set(Key)
if len(sys.argv) is not 1:
    res = CF.person.create(personGroupId, str(sys.argv[1]))
    print(res)
    extractId = str(sys.argv[1])[-2:]
    connect = sqlite3.connect("Face-DataBase")
    cmd = "SELECT * FROM Students WHERE ID = " + extractId
    cursor = connect.execute(cmd)
    isRecordExist = 0
    for row in cursor:                                                          # checking wheather the id exist or not
        isRecordExist = 1
    if isRecordExist == 1:                                                      # updating name and roll no
        connect.execute("UPDATE Students SET personID = ? WHERE ID = ?",(res['personId'], extractId))
    connect.commit()                                                            # commiting into the database
    connect.close()
    print ("Person ID successfully added to the database")

感谢您的帮助。

4

1 回答 1

0

首先检查personGroupId您传入的 确实存在。您可以通过向/persongroups/:id. 现场演示在这里

如果存在,则很可能您的 API 密钥区域与默认区域(即美国西部)不匹配。

您可以尝试将此添加到您的代码中:

BASE_URL = 'https://YOUR-REGION.api.cognitive.microsoft.com/face/v1.0/'
CF.BaseUrl.set(BASE_URL)
于 2018-04-05T06:09:48.277 回答