'How to iterate through a folder in Python, to pass the values to an api

I am trying to pass images to an api in Python. I can get a response when I pass in one online image, but I have 1000 images to do, so I am also trying to find a way for python to loop through the image folder and pass in the images. The below code is what I have so far for a single online image.

import requests

headers = {
    "app_id": "XXXX",
    "app_key": "XXXXXXXXXXX"
}

payload = '{"image": "https://www.biography.com/.image/ar_1:1%2Cc_fill%2Ccs_srgb%2Cfl_progressive%2Cq_auto:good%2Cw_1200/MTE4MDAzNDEwNzg5ODI4MTEw/barack-obama-12782369-1-402.jpg"}'

url = "http://api.kairos.com/detect"

r = requests.post(url, data=payload, headers=headers)
print r.content

anyone know how I can add a loop to iterate through a folder of images?

Thanks :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source