在使用face ++ API的for循环中发出post请求
问题描述:
我需要一些帮助,我的代码在这里。我是使用API的新手,我有一个包含100000张照片的文件,我想检测和分析。直到现在,我写的代码我只能检测到一个图像,但是当我尝试测试更多的时候,它不会让我做检测。在face ++免费APIKEY中,每秒只能发出1个请求,这就是为什么我有time.sleep()。此外,如果我在多个图像中测试代码,可以说2-3个图像,那么它只会将第一个图像的结果保存在csv中。你能帮我解决这个问题吗?在使用face ++ API的for循环中发出post请求
import requests
for i in range(1,100000):
http_url="https://api-us.faceplusplus.com/facepp/v3/detect"
path='..'
key=".."
secret=".."
data={ "api_key": "..","api_secret":".."}
files= {"image_file": open(path+str(i) +".jpg", 'rb')}
response=requests.post(http_url,data=data,files=files)
time.sleep(2)
req_con=response.content.decode('utf-8')
req_dict=JSONDecoder().decode(req_con)
time.sleep(2)
file = open("out.csv", "wb")
file.write(response.content)
答
尝试写入CSV作为附加模式 file = open("out.csv", "ab")
你再次覆盖同一行。