0

私はtest1.jpgtest2.jpgをどこに置くのか分かりません。Microsoft Face ApiがPythonを検証する

公式APIサイトはこちら

...私は、このコードに多くの時間を変更しましたが、私はできません:https://dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523aあなたはrequestsを使用する必要があります

{"error":{"code":"BadArgument","message":"Request body is invalid."}}

import httplib, urllib, base64 

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

params = urllib.urlencode({ 
}) 

try: 
    conn = httplib.HTTPSConnection('api.projectoxford.ai') 
    conn.request("POST", "/face/v1.0/verify?%s" % params, "{body}", headers) 
    response = conn.getresponse() 
    data = response.read() 
    print(data) 
    conn.close() 
except Exception as e: 
    print("[Errno {0}] {1}".format(e.errno, e.strerror)) 

答えて

1

ライブラリ代わりに:

import requests,json 

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

body = { 
"faceId":"c5c24a82-6845-4031-9d5d-978df9175426", 
"peronId":"815df99c-598f-4926-930a-a734b3fd651c", 
"personGroupId":"sample_group" 
} 

try: 

    r = requests.post("https://api.projectoxford.ai/face/v1.0/verify", json=body,headers=headers) 
    print(r.json()) 
except Exception as e: # Do whatever error handling you need here. 
    print("[Errno {0}] {1}".format(e.errno, e.strerror)) 
関連する問題