我需要一些帮助来处理我的代码。我是使用API的新手,我有一个包含100000张照片的文件,我想要检测和分析。到目前为止,使用我编写的代码,我只能检测到一个图像,但当我尝试测试更多图像时,它不会让我进行检测。在face++免费的APIKEY中,每秒只能发出一次请求,这就是我使用time.sleep()的原因。此外,如果我在多个图像中测试代码,假设有2-3个图像,那么它只将第一个图像的结果保存在csv中。你能帮我解决这个问题吗?
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)发布于 2018-02-01 04:21:00
尝试以附加模式file = open("out.csv", "ab")的形式写入csv,您将再次覆盖同一行。
https://stackoverflow.com/questions/46457512
复制相似问题