{"record":{"id":"8c3c59b871ce1355","repo":"dotnet/runtime","slug":"failed-to-download-url-status-code-response-s","errorCode":null,"errorMessage":"Failed to download {url}, Status Code: {response.status}","messagePattern":"Failed to download (.+?), Status Code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"eng/common/cross/install-debs.py","lineNumber":40,"sourceCode":"    attempt = 0\n    while attempt < max_retries:\n        try:\n            async with session.get(url, timeout=aiohttp.ClientTimeout(total=timeout)) as response:\n                if response.status == 200:\n                    with open(dest_path, \"wb\") as f:\n                        content = await response.read()\n\n                        # verify checksum if provided\n                        if checksum:\n                            sha256 = hashlib.sha256(content).hexdigest()\n                            if sha256 != checksum:\n                                raise Exception(f\"SHA256 mismatch for {url}: expected {checksum}, got {sha256}\")\n\n                        f.write(content)\n                    print(f\"Downloaded {url} at {dest_path}\")\n                    return\n                else:\n                    raise Exception(f\"Failed to download {url}, Status Code: {response.status}\")\n        except (asyncio.CancelledError, asyncio.TimeoutError, aiohttp.ClientError) as e:\n            print(f\"Error downloading {url}: {type(e).__name__} - {e}. Retrying...\")\n\n        attempt += 1\n        await asyncio.sleep(retry_delay)\n\n    raise Exception(f\"Failed to download {url} after {max_retries} attempts.\")\n\nasync def download_deb_files_parallel(mirror, packages, tmp_dir):\n    \"\"\"Download .deb files in parallel.\"\"\"\n    os.makedirs(tmp_dir, exist_ok=True)\n\n    tasks = []\n    timeout = aiohttp.ClientTimeout(total=60)\n    async with aiohttp.ClientSession(timeout=timeout) as session:\n        for pkg, info in packages.items():\n            filename = info.get(\"Filename\")\n            if filename:","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/eng/common/cross/install-debs.py#L22-L58","documentation":"download_file received an HTTP response with a status code other than 200 (e.g. 404 Not Found, 403 Forbidden, 500/502/503 server error). The exception captures the status so the caller can see why the .deb or Release file could not be fetched. The function then retries up to max_retries before giving up.","triggerScenarios":"Fetching a .deb by the path stored in the Packages index, but the mirror returns 404 (package retired, suite changed, arch mismatch). Or a 403/5xx due to mirror problems. Raised at install-debs.py:40 inside the retry loop.","commonSituations":"Pointing --suite at a released Debian/Ubuntu version where a package was removed. Wrong --arch (e.g. arm64 against an amd64-only mirror). Mirror rate-limiting returning 403. Mirror maintenance returning 5xx.","solutions":["Verify --arch and --suite match a mirror layout that actually contains the package (browse the mirror's dists/<suite>/ directory).","Switch to a mirror that still hosts the package, or pick a newer --suite.","If 4xx is intermittent (rate limit/CDN), wait and retry; for 5xx pick a different mirror.","Make sure the base-packages list (dpkg, busybox, libc6, etc.) is available on the chosen mirror."],"exampleFix":"# before\npython3 install-debs.py --arch loong64 --suite sid --mirror http://deb.debian.org/debian libc6\n# 404: sid does not carry loong64 at deb.debian.org\n\n# after\npython3 install-debs.py --arch loong64 --suite sid --mirror http://ftp.ports.debian.org/debian-ports libc6","handlingStrategy":"retry","validationCode":"# Pre-flight: probe a HEAD request for each .deb URL before the build.\nimport aiohttp, asyncio\nasync def probe(url: str) -> int:\n    async with aiohttp.ClientSession() as s:\n        async with s.head(url) as r:\n            return r.status\n\n# If status != 200, fix --arch/--suite/--mirror before running install-debs.py.","typeGuard":null,"tryCatchPattern":"# download_file already retries 3x. For 4xx, fix the mirror/suite/arch instead of retrying:\ntry:\n    main()\nexcept Exception as e:\n    if 'Status Code: 40' in str(e):\n        print('Package path not found; check --arch/--suite/--mirror.')\n        sys.exit(2)\n    raise","preventionTips":["Verify --arch and --suite against the mirror's dists/ layout before building.","Use official mirrors that still host the chosen suite.","HEAD-probe each .deb URL in CI before the full rootfs build."],"tags":["dotnet-rootfs","debian","download","http","network","python"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}