requests 패키지 필요
pip install requests
import time
import requests
# 요청 간 대기 시간
request_interval_second = 15
# 요청 조합 리스트
request_configs = [
{
"method": "GET",
"url": "<https://d6a392fa87gv8.cloudfront.net/v1/order?id=1234>",
"headers": {},
"body": None
},
{
"method": "GET",
"url": "<https://d6a392fa87gv8.cloudfront.net/v1/customer?id=1234>",
"headers": {},
"body": None
},
{
"method": "GET",
"url": "<https://d6a392fa87gv8.cloudfront.net/v1/product?id=1234>",
"headers": {},
"body": None
},
{
"method": "GET",
"url": "<https://d6a392fa87gv8.cloudfront.net>",
"headers": {},
"body": None
},
]
def is_html_response(response):
content_type = response.headers.get("Content-Type", "")
return "text/html" in content_type.lower()
while True:
for config in request_configs:
try:
method = config["method"].upper()
url = config["url"]
headers = config["headers"]
body = config["body"]
if method == "GET":
response = requests.get(url, headers=headers, params=body)
elif method == "POST":
response = requests.post(url, headers=headers, json=body)
elif method == "PUT":
response = requests.put(url, headers=headers, json=body)
elif method == "DELETE":
response = requests.delete(url, headers=headers, json=body)
else:
print(f"[{time.strftime('%H:%M:%S')}] ❌ {method} {url}")
print(f"❌ Unsupported method: {method}\\n")
continue
if response.status_code < 400:
print(f"[{time.strftime('%H:%M:%S')}] ✅ {method} {url}")
else:
print(f"[{time.strftime('%H:%M:%S')}] ❌ {method} {url}")
print(f"Response Code: {response.status_code}")
if is_html_response(response):
print("Response Body: [HTML content suppressed]\\n")
else:
print(f"Response Body: {response.text}\\n")
except Exception as e:
print(f"[{time.strftime('%H:%M:%S')}] ❌ {method} {url}")
print(f"Error: {e}\\n")
time.sleep(request_interval_second)