我不明白我在正文中写了什么。我不会在那里写什么,在创建个人群组时总是会产生错误。
import http.client, urllib.request, urllib.parse, urllib.error, base64, requests
headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'XXXXXXXXXXXXXXXX',
}
params = urllib.parse.urlencode({
# Request parameters
# "personGroupId": "1",
"name": "MyFace",
"userData": "User-provided data attached to the person.",
"recognitionModel": "recognition_02"
})
try:
conn = http.client.HTTPSConnection('XXXXX.cognitiveservices.azure.com')
conn.request("PUT", "/face/v1.0/persongroups/{personGroupId}%s" % params, "{body", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Excepion as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
试试这个:
import json,http.client, urllib.request, urllib.parse, urllib.error, base64
headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '<your key here>',
}
params ={
"name": "<your person group name here>",
"userData": "user-provided data attached to the person group.",
"recognitionModel": "recognition_02"
}
conn = http.client.HTTPSConnection('<your endpoint name here>.api.cognitive.microsoft.com')
conn.request("PUT", "/face/v1.0/persongroups/%s" % params.get("name"), json.dumps(params), headers)
response = conn.getresponse()
data = response.read()
print(data)
print(response.getcode())
conn.close()
如果您得到一个200的代码,则表示已经成功创建了一个组。