Merge requests.get with python

Viewed 140

Having this two request how can i merge the results in one variable?

listone=requests.get(URL + API_URL + endpoint,
                            headers=API_HEADER,
                            params=getparams)

#some missing code that do stuff


listtwo=requests.get(URL + API_URL + endpoint,
                            headers=API_HEADER,
                            params=getparams)

Thanks

1 Answers
url_header_list = [
    (url1, headers1),
    (url2, headers2),
]

items = []
# You can change your headers and url in any way you want, not just like that
for url, headers in url_header_list:
    # And this you need to do for each pair of url and headers
    response = requests.get(url, headers=headers).json()
    items.extend(response['items'])

items will contain all the items from each response.

Related