I am in the process of creating a Python script that will allow me to process multiple GET requests by using a "for" loop. However, I am not getting the results that I expect. Here is what my code looks like:
import requests
import json
authorization_code = "api:122222:1111112:LA5"
members = [12345,1234567]
for member in members:
url = "http://api.example.com/v1.14/member?id="+str(member)
header = {"Authorization": authorization_code}
response = requests.get(url, headers=header)
member_check = json.loads(response.text)
final_member_status = member_check["response"]["member"]["is_expired"]
print str(member) + " expired status: " + str(final_member_status)
In this example, I see member "1234567" printing out as part of my structure at the end. What I am expecting is the loop to go through each one of these members and make a GET request for each one and then return a specific key value for each member (in this case, the key is called "is_expired". Therefore, I should see:
member 12345 expired status: false
member 1234567 expired status: false
If anyone could help I would appreciate it. My guess is that I am not using my loop correctly or that I have in the wrong place.
Thanks.