Fix: Add page limit to debug script to prevent infinite loops
This commit is contained in:
@@ -100,9 +100,18 @@ def fetch_all_packages():
|
||||
version = "2022-01-01"
|
||||
all_packages = []
|
||||
current_token = ""
|
||||
page_count = 0
|
||||
MAX_PAGES = 15 # 🛑 Safety Limit for Debugging
|
||||
|
||||
while True:
|
||||
try:
|
||||
page_count += 1
|
||||
if page_count > MAX_PAGES:
|
||||
print(
|
||||
f"⚠️ Reached MAX_PAGES ({MAX_PAGES}). Stopping fetch to prevent infinite loop."
|
||||
)
|
||||
break
|
||||
|
||||
payload = {
|
||||
"ResourceType": "Package",
|
||||
"MaxResults": "20",
|
||||
@@ -111,7 +120,7 @@ def fetch_all_packages():
|
||||
headers, body = get_signed_headers(action, version, payload)
|
||||
url = f"https://{HOST}/?Action={action}&Version={version}"
|
||||
|
||||
print(f" POST {url}")
|
||||
print(f" [Page {page_count}] POST {url} (Token: {current_token[:10]}...)")
|
||||
response = requests.post(url, data=body, headers=headers, timeout=60)
|
||||
|
||||
if response.status_code != 200:
|
||||
@@ -128,8 +137,18 @@ def fetch_all_packages():
|
||||
all_packages.extend(items)
|
||||
|
||||
next_token = data.get("Result", {}).get("NextToken", "")
|
||||
if not next_token or next_token == current_token:
|
||||
|
||||
# Debug Token Transition
|
||||
# print(f" Token: '{current_token}' -> '{next_token}'")
|
||||
|
||||
if not next_token:
|
||||
print(" ✅ No NextToken. Done.")
|
||||
break
|
||||
|
||||
if next_token == current_token:
|
||||
print(" ⚠️ NextToken did not change. Stopping.")
|
||||
break
|
||||
|
||||
current_token = next_token
|
||||
time.sleep(0.2)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user