Python循环请求接口
import requests
import time
接口URL
url = ‘http://example.com/api/ii_app_spi_send_config’
请求头
headers = {
‘Content-Type’: ‘application/json’,
}
请求参数
data = {
# 根据实际情况填写
“key1”: “value1”,
“key2”: “value2”
}
def call_api():
count = 0
while True:
try:
response = requests.post(url, headers=headers, json=data)
print(f"请求 {count + 1}: 状态码 {response.status_code}")
count += 1
if count % 100 == 0:
print(“已请求100次,暂停5秒…”)
time.sleep(5)
except Exception as e:
print(f"请求失败: {e}")
if name == “main”:
call_api()