debug: print response content-type and body on non-Excel download
Helps identify what the server is actually returning when the download URL doesn't serve the xlsx file. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+9
-1
@@ -32,7 +32,15 @@ def main():
|
||||
print(f"Downloading ELO sheet…", flush=True)
|
||||
resp = requests.get(DOWNLOAD_URL, timeout=120, headers={"User-Agent": "Mozilla/5.0"})
|
||||
resp.raise_for_status()
|
||||
print(f"Downloaded {len(resp.content):,} bytes", flush=True)
|
||||
|
||||
content_type = resp.headers.get("Content-Type", "")
|
||||
print(f"Downloaded {len(resp.content):,} bytes Content-Type: {content_type}", flush=True)
|
||||
|
||||
# Diagnose non-Excel responses before attempting to parse
|
||||
if "html" in content_type.lower() or not resp.content.startswith(b"PK"):
|
||||
print("ERROR: Response is not an Excel/ZIP file. First 500 chars:", flush=True)
|
||||
print(resp.content[:500].decode("utf-8", errors="replace"), flush=True)
|
||||
sys.exit(1)
|
||||
|
||||
wb = openpyxl.load_workbook(BytesIO(resp.content), read_only=True, data_only=True)
|
||||
ws = wb.active
|
||||
|
||||
Reference in New Issue
Block a user