0

I have a list of API links, and I'm trying to get the data from these API links.

If my list of API links looks like this:

api_links = ['https://api.blahblah.com/john', 'https://api.blahblah.com/sarah', 'https://api.blahblah.com/jane']

How can I get a list of loaded data from these API links? I'm getting an error message when doing this code:

response_API = requests.get([(x) for x in api_links])

Which is preventing me from loading the data here:

data = response_API.text
data_lst = json.loads(data)

Where am I going wrong?

0

2 Answers 2

1

change

response_API = requests.get([(x) for x in api_links])

to

response_API = [requests.get(x) for x in api_links]

responce_api will be a dict of requests object.

Sign up to request clarification or add additional context in comments.

Comments

0

The function requests.get take as first argument an URL, not a list of them.

You want to call this function several times with one string, instead of one time with a list of strings.

Like this with a for loop :

for api_link in api_links:
    response_API = requests.get(api_link)
    data = response_API.text
    data_lst = json.loads(data)
    # Process further the data for the current api_link 

The use of comprehension lists may not be a good idea here, as the process to do on each API link is not trivial.

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.