我的API获取请求最多只能给我100个,如何循环它以获取所有商品?

时间:2019-04-17 05:53:58

标签: python api swagger

SO Im正在使用Python3从API中获取所有项目,这个问题是我运行脚本时只显示100,而我知道它们已超过1000。

我尝试使用while循环,但由于重复相同的结果而失败

import requests
import json
def get_list_call(offset): 

    url = "https://link.com/monitoring/v1/switches"

    querystring = {"limit":"%s"%limit,"offset":"%s"% offset}
    headers = {
        'Authorization': "Bearer Token",
        'cache-control': "no-cache",
        }

    response = requests.request("GET", url, headers=headers,params=querystring)

    return(response.text)

result = get_list_call(0)
data_json = json.loads(result)
count = (data_json['count'])
print (count)

我看到20个项目的结果 数= 20

1 个答案:

答案 0 :(得分:0)

谢谢你们的评论,所以我能够在API中使用标记总计,向我显示项目的总数,然后使用while循环将其全部获取。

谢谢