我正在使用API来执行返回JSON的HTTP请求。但是,调用api取决于要指示的开始页和结束页,例如:
def API_request(URL):
while(True):
try:
Response = requests.get(URL)
Data = Response.json()
return(Data['data'])
except Exception as APIError:
print(APIError)
continue
break
def build_orglist(start_page, end_page):
APILink = ("http://sc-api.com/?api_source=live&system=organizations&action="
"all_organizations&source=rsi&start_page={0}&end_page={1}&items_"
"per_page=500&sort_method=&sort_direction=ascending&expedite=1&f"
"ormat=json".format(start_page, end_page))
return(API_request(APILink))
了解您是否不在现有页面的唯一方法是,当JSON为空时,如this。
如果我想在每个页面上异步执行多个build_orglist
,直到我到达终点(Null JSON),我该怎么办?