0

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.

2
  • is the code here indented as your code or a typing error? Commented Mar 24, 2017 at 17:03
  • My code was NOT indented and this fixed the issue. Thanks! Commented Mar 24, 2017 at 18:57

1 Answer 1

2

Indentation, you are welcome:

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.