【问题标题】:Error when calling Cognitive Face API调用认知人脸 API 时出错
【发布时间】:2018-04-05 14:09:48
【问题描述】:

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

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")

感谢您的帮助。

【问题讨论】:

    标签: python-3.x face-api


    【解决方案1】:

    首先检查您传入的personGroupId 是否确实存在。您可以通过向 /persongroups/:id 发出 GET 来完成此操作。现场演示here.

    如果存在,那么您的 API 密钥区域很可能与默认区域 (which is West US) 不匹配。

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

    BASE_URL = 'https://YOUR-REGION.api.cognitive.microsoft.com/face/v1.0/'
    CF.BaseUrl.set(BASE_URL)
    

    【讨论】:

      猜你喜欢
      • 2018-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-22
      • 2016-10-10
      • 2017-05-25
      • 2017-09-26
      • 2018-11-27
      相关资源
      最近更新 更多