4. Query task results

1 Function description

Query task results, and obtain task status, queuing progress, and download link of results.

Note that each call will consume 0.1 coins.

2 Request method

method:POST URL :{ApiUrl}/api/inf/get_result

3 Request parameter

nametypedescribesample

openId

string

your openId

apiKey

string

our apiKey

infId

long

task id

2880

    # Tasks usually take between 10 minutes and 90 seconds to complete, don't search too fast
    # Cold startup, the image to boot, take 10 minutes to complete
    # If the mirror is on and there is no queued task ahead, the completion time is about 90 seconds
    # The query interval is recommended to be longer, too frequent will be blocked by the firewall ip
    for _ in range(30):
        params = {'openId':OpenId, 'apiKey':ApiKey, 'infId':infId}
        session = requests.session()
        ret = requests.post(f"{ApiUrl}/api/inf/get_result", data=json.dumps(params))
        if ret.status_code==200:
            print(ret.json())
            if 'data' in ret.json():
                data = ret.json()['data']
                """
                    【success】
                    {'code': 200, 'msg': 'ok', 'data': {'bmi': 0.000402367, 'body_url': '', 
                    'cost': 5.0, 'hairOcclued': 0, 'height': 0.0, 'id': 3619, 'imgUrl1': '', 
                    'imgUrl2': '', 'imgUrl3': '', 'infInfo': '', 'infInfoEn': '', 'ipId': '', 'isApi': 1, 
                    'modelBmi': 0.0, 'openId': 'ovB-x66u8', 'position': 0, 
                    'shareUser': -1, 'showUrl': '', 'state': 1, 'tempId': 208, 'useInfId': -1, 
                    'weight': 0.0}}
                """
                print("The current task queue position is: ", data['position'])
                print("The current task status is: ", data['state'])

                if data['state']==2:
                    pose_url = OssUrl+data['body_url']
                    out_url = OssUrl+data['showUrl']
                    urlretrieve(pose_url, out_pose_path)
                    urlretrieve(out_url, out_img_path)
                    print(f"Mission accomplished!", flush=True)
                    break
                elif data['state']==1:
                    position = data['position']
                    print(f"The task is being queued. Queued position:{position}", flush=True)
                elif data['state']==-1:
                    infInfoEn = data['infInfoEn']
                    print(f"Task failed. An error message was reported:{infInfoEn}", flush=True)
                    """
                        An example returns the result
                        {'code': 200, 'msg': 'ok', 'data': {'bmi': 0.000402367, 'body_url': '', 
                        'cost': 5.0, 'hairOcclued': 0, 'height': 0.0, 'id': 3653, 'imgUrl1': '', 
                        'imgUrl2': '', 'imgUrl3': '', 
                        'infInfo': '没有检测到脸部,请上传正确的人体试衣照片', 
                        'infInfoEn': 'No face was detected. Please upload the correct human fitting photo.', 
                        'ipId': '', 'isApi': 1, 'modelBmi': 0.0, 
                        'openId': 'ovB-x63dKsdfu8', 'position': 0, 'shareUser': -1,
                         'showUrl': '', 'state': -1, 'tempId': 208, 'useInfId': -1, 'weight': 0.0}}
                    """
                    break
                elif data['state']==-2:
                    print("not enough coins", flush=True)
                    break

        time.sleep(60)

4 Respond

  • success

{'code': 200, 'msg': 'ok', 'data': {'bmi': 0.000402367, 'body_url': '', 
'cost': 5.0, 'hairOcclued': 0, 'height': 0.0, 'id': 3619, 'imgUrl1': '', 
'imgUrl2': '', 'imgUrl3': '', 'infInfo': '', 'infInfoEn': '', 'ipId': '', 'isApi': 1, 
'modelBmi': 0.0, 'openId': 'ovB-x63dKsdfu8', 'position': 0, 
'shareUser': -1, 'showUrl': '', 'state': 1, 'tempId': 208, 'useInfId': -1, 
'weight': 0.0}}
  • failed

{'code': 200, 'msg': 'ok', 'data': {'bmi': 0.000402367, 'body_url': '', 'cost': 5.0, 'hairOcclued': 0, 'height': 0.0, 'id': 3653, 'imgUrl1': '', 'imgUrl2': '', 'imgUrl3': '', 'infInfo': '没有检测到脸部,请上传正确的人体试衣照片', 'infInfoEn': 'No face was detected. Please upload the correct human fitting photo.', 'ipId': '', 'isApi': 1, 'modelBmi': 0.0, 'openId': 'ovB-x639B8QwdfF7kQYS9QKdK6u8', 'position': 0, 'shareUser': -1,'showUrl': '', 'state': -1, 'tempId': 208, 'useInfId': -1, 'weight': 0.0}}

5 Download Results

    if data['state']==2:
        pose_url = OssUrl+data['body_url']
        out_url = OssUrl+data['showUrl']
        urlretrieve(pose_url, out_pose_path)
        urlretrieve(out_url, out_img_path)
        print(f"Mission accomplished!", flush=True)
        break

Last updated