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_fast_result

3 Request parameter

nametypedescribesample

openId

string

your openId

apiKey

string

our apiKey

infId

long

task id

2880

    for _ in range(30):
        params = {'openId':OpenId, 'apiKey':ApiKey, 'infId':infId}
        session = requests.session()
        ret = requests.post(f"{ApiUrl}/api/inf/get_fast_result", data=json.dumps(params))
        if ret.status_code==200:
            print(ret.json())
            if 'data' in ret.json():
                data = ret.json()['data']
                """
                    {
                        "code": 200,
                        "msg": "ok",
                        "data": {
                            "auto_crop": 0,
                            "auto_mask": 0,
                            "bodyUrl": "ClothData/Publics/Users/ovB-x639B8QwdfF7kQYS9QKdK6u8/FastInfs/QKGBFQ6618/res_src.jpg",
                            "caption": "",
                            "category": 2,
                            "cost": 0.0,
                            "denoise_steps": 0,
                            "id": 6618,
                            "infInfo": "result 0",
                            "infInfoEn": "result 0",
                            "ipId": "",
                            "isApi": 1,
                            "maskUrl": "ClothData/Publics/Users/ovB-x639B8QwdfF7kQYS9QKdK6u8/FastInfs/QKGBFQ6618/res_mask.jpg",
                            "openId": "ovB-x639B8QwdfF7kQYS9QKdK6u8",
                            "position": 0,
                            "showUrl": "ClothData/Publics/Users/ovB-x639B8QwdfF7kQYS9QKdK6u8/FastInfs/QKGBFQ6618/res_img.jpg",
                            "state": 2,
                            "suffix": "QKGBFQ"
                        }
                    }
                """
                # In fact, you only need to pay attention to these 3 fields
                print("The current task queue position is: ", data['position'])
                print("The current task status is: ", data['state'])

                if data['state']==2:
                    urlretrieve(OssUrl+data['bodyUrl'], out_pose_path)
                    urlretrieve(OssUrl+data['showUrl'], out_img_path)
                    urlretrieve(OssUrl+data['maskUrl'], out_mask_path)
                    print(f"The task has been completed!", flush=True)
                    break
                elif data['state']==1:
                    position = data['position']
                    print(f"The task is being queued for execution, and the queue position:{position}", flush=True)
                elif data['state']==-1:
                    infInfoEn = data['infInfoEn']
                    print(f"Task failed, error message reported:{infInfoEn}", flush=True)
                    """
                        An example returns results
                        {'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}}
                    """
                    break
                elif data['state']==-2:
                    print("no coins", flush=True)
                    break

        time.sleep(60)

4 Respond

  • success

{
    "code": 200,
    "msg": "ok",
    "data": {
        "auto_crop": 0,
        "auto_mask": 0,
        "bodyUrl": "ClothData/Publics/Users/ovB-x639B8QwdfF7kQYS9QKdK6u8/FastInfs/QKGBFQ6618/res_src.jpg",
        "caption": "",
        "category": 2,
        "cost": 0.0,
        "denoise_steps": 0,
        "id": 6618,
        "infInfo": "result 0",
        "infInfoEn": "result 0",
        "ipId": "",
        "isApi": 1,
        "maskUrl": "ClothData/Publics/Users/ovB-x639B8QwdfF7kQYS9QKdK6u8/FastInfs/QKGBFQ6618/res_mask.jpg",
        "openId": "ovB-x639B8QwdfF7kQYS9QKdK6u8",
        "position": 0,
        "showUrl": "ClothData/Publics/Users/ovB-x639B8QwdfF7kQYS9QKdK6u8/FastInfs/QKGBFQ6618/res_img.jpg",
        "state": 2,
        "suffix": "QKGBFQ"
    }
}
  • failed

{
    "code": 500,
    "msg": "前端数据被黑客篡改,已记录上报公安机关!"
}

5 Download Results

out_url = OssUrl+data['showUrl']
urlretrieve(out_url, out_img_path)

Last updated