Face++ API调用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tinyzhao/article/details/55224183

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

import requests
from json import JSONDecoder

http_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)

是不是简洁了很多。

猜你喜欢

转载自blog.csdn.net/tinyzhao/article/details/55224183