Face++ API调用

来源:互联网 发布:国产007经典视频知乎 编辑:程序博客网 时间:2024/05/16 05:01

Face++提供的API接入示例代码太过复杂,http请求需要使用Multipart方式,代码居然真的自己组装了一个multipart请求体,没有充分使用轮子啊。我用轮子把这个过程简化一下,代码如下:

import requestsfrom json import JSONDecoderhttp_url = "https://api-cn.faceplusplus.com/facepp/v3/detect"key = "your_key"secret = "your_secret"filepath = "image/1.jpg"data = {"api_key": key, "api_secret": secret, "return_landmark": "1"}files = {"image_file": open(filepath, "rb")}response = requests.post(http_url, data=data, files=files)req_con = response.content.decode('utf-8')req_dict = JSONDecoder().decode(req_con)print(req_dict)

是不是简洁了很多。

0 0