2017-09-27 52 views
0

我需要一些幫助,我的代碼在這裏。我是使用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) 

回答

0

嘗試寫入CSV作爲附加模式 file = open("out.csv", "ab") 你再次覆蓋同一行。