0

I'm trying to enroll person profile pic's using kairos API. I have a following python code.

My python script:

#!/usr/bin/python3

import requests
import io
import http.client
import base64
import json
import glob, os
from os.path import basename

dir_path = "/home/Kairos/profiles/msc/" 

os.chdir(dir_path)

for file in glob.glob("*.*"):
    img_path = file
    print(img_path)
    files = {'image': (img_path, open(dir_path + img_path, 'rb'), 'image/jpg', {'Expires': '0'})}

    headers = {
        'app_id': "xxxx",
        'app_key': "xxxxxxxxxxxxxxxxxxxxxx",
    }

    values_enrol = {
       'subject_id':'msc',
       'gallery_name':'mscGallary'
    }

    res = requests.post('https://api.kairos.com/enroll', headers=headers, files=files, data=values_enrol)

    print(res.content)

But, I'm getting an error :

 "Errors": [
        {
            "ErrCode": 1002,
            "Message": "subject_id one or more required parameters are missing"
        },
        {
            "ErrCode": 1002,
            "Message": "gallery_name one or more required parameters are missing"
        }
    ]
}

What am I doing wrong here? Please someone help me.

Thanks in advance.

msc
  • 33,420
  • 29
  • 119
  • 214

1 Answers1

0

I found solution:

def build_payload(file):    
    if file is not None:
        image = extract_base64_contents(file)
    else:
        image = url

    values_enrol = {
       'image': image,
       'gallery_name': sys.argv[1],
    }

    return dict(values_enrol)

def extract_base64_contents(file):
    with open(file, 'rb') as fp:
        image = base64.b64encode(fp.read()).decode('ascii')
    return image
msc
  • 33,420
  • 29
  • 119
  • 214