我想使用請求庫向 python 中的 api 發送請求。當我想第一次呼叫 api 時,我應該發送一個引數,但在第一次呼叫成功后,引數不應該發送。我該如何處理這種情況?示例代碼:
while True:
firstTime = True -> This is the first time parameter
params = {
"accountNo": self.DEPOSIT,
"lastTranKey": None if firstTime is True else "",
"fromDate": fromDate,
"toDate": toDate,
"pageSize": length,
}
response = requests.post(
url="",
json=params,
timeout=50
)
if response.status_code == 200:
firstTime = False
uj5u.com熱心網友回復:
你可以放在firstTime回圈之前,做一次
firstTime = True
while True:
params = {
"accountNo": self.DEPOSIT,
"lastTranKey": None if firstTime else "",
"fromDate": fromDate,
"toDate": toDate,
"pageSize": length,
}
response = requests.post(
url="",
json=params,
timeout=50
)
if response.status_code == 200:
firstTime = False
uj5u.com熱心網友回復:
在回圈之前,將第一次標志設定為真。然后在回圈的底部,將其設定為 false。
firstTime = True
while True:
# do stuff
firstTime = False
uj5u.com熱心網友回復:
您可以使用if else statement.
first_time = True
while True:
if first_time:
#do the stuff only ones
if response.status_code == 200:
firstTime = False
else:
#do stuff for rest of the time
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/489168.html
