Skip to content Skip to sidebar Skip to footer

Error While Trying To Upload File Using Kairos

Iam using kairos api for face recognition .Iam trying to enroll an image.The documentation here says it also accepts base64 encode photos.So I have encoded the image using base 64

Solution 1:

Don't encode your photos. Probably they accept it, but its harder to pass. Check this solution:

import requests

files = {"image": (filename,open(location+'/'+filename,"rb"))}
payload= {"subject_id":"Abhishek",
          "gallery_name":"MyGallery"}
headers={'Content-Type':'application/json',
         'app_id':'app_id',
         'app_key':'app_key'}
response = requests.post('https://api.kairos.com/enroll',headers=headers,data=payload,files=files,verify=False)
print response.text 

Solution 2:

I found the answer to the problem. You can try reading the image not using cv2, but as simple raw binary. cv2 reads it into a numpy array and you are encoding a numpy array. Reading like a simple file works for me, like below

withopen ('messi.jpg','rb') as imgFh:
    img = imgFh.read()

Solution 3:

Try this.

import cv2
import requests
import base64
import json

encoded_string = base64.b64encode(open("Face-images/Subject 9.jpg", 
'r').read())
payload_dict = {
    "image":encoded_string,
    "subject_id": "Abhishek",
    "gallery_name": "MyGallery"
}
payload = json.dumps(payload_dict)
headers={
'Content-Type':'application/json',
'app_id':'app_id',
'app_key':'app_key'
}
request = Request('https://api.kairos.com/enroll', data=payload, 
headers=headers)
response_body = urlopen(request).read()
print(response_body)

Post a Comment for "Error While Trying To Upload File Using Kairos"