{"record":{"id":"08511aee507f286e","repo":"OpenBB-finance/OpenBB","slug":"failed-to-download-document-from-url-status-cod","errorCode":null,"errorMessage":"Failed to download document from {url}. Status code: {response.status}","messagePattern":"Failed to download document from (.+?)\\. Status code: (.+?)","errorType":"http","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/models/weather_bulletin_download.py","lineNumber":84,"sourceCode":"                    ValueError(\n                        f\"Invalid URL '{url}'. Only URLs from 'esmis.nal.usda.gov' are supported.\"\n                    )\n                )\n            if not url.lower().endswith(\".pdf\"):\n                raise OpenBBError(\n                    ValueError(\n                        f\"Invalid URL '{url}'. Only PDF documents are supported.\"\n                    )\n                )\n\n        try:\n            async with await get_async_requests_session() as session:\n                session._max_field_size = 32768  # pylint: disable=protected-access\n\n                for url in urls:\n                    async with await session.get(url) as response:\n                        if response.status != 200:\n                            raise OpenBBError(\n                                ValueError(\n                                    f\"Failed to download document from {url}. Status code: {response.status}\"\n                                )\n                            )\n                        content_bytes = await response.read()\n                        results[url] = content_bytes\n\n            return results\n        except Exception as e:\n            raise OpenBBError(e) from e\n\n    @staticmethod\n    def transform_data(\n        query: GovernmentUsWeatherBulletinDownloadQueryParams,\n        data: dict,\n        **kwargs: Any,\n    ) -> list[GovernmentUsWeatherBulletinDownloadData]:\n        \"\"\"Transform the raw PDF content into the data model.\"\"\"","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/models/weather_bulletin_download.py#L66-L102","documentation":"Raised during the aiohttp download loop when response.status is not 200 for an allowlisted PDF URL. The generic except Exception at the end of extract_data re-wraps it into OpenBBError, so the caller sees this message regardless of the underlying status. It means the URL passed validation but the server did not return the file.","triggerScenarios":"A valid-looking esmis.nal.usda.gov/*.pdf URL that has been moved or removed (404), server-side errors (5xx), or rate limiting (429) when downloading several bulletins in one call.","commonSituations":"Stale URLs harvested long ago; batch downloads of many bulletins triggering throttling; ESMIS maintenance windows.","solutions":["Verify the URL opens in a browser; if 404, re-fetch a fresh URL from the weather_bulletin endpoint.","For 429/5xx, reduce batch size and retry after a delay.","Check that only existing bulletin dates/years are requested."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    res = obb.economy.gov.weather_bulletin_download(urls=[u])\nexcept OpenBBError as e:\n    if \"Failed to download document\" in str(e):\n        time.sleep(5)\n        res = obb.economy.gov.weather_bulletin_download(urls=[u])\n    else:\n        raise","preventionTips":["Re-fetch fresh URLs from weather_bulletin instead of storing them long-term.","Batch downloads modestly and add delays to avoid USDA throttling.","Verify each URL with a HEAD request before the bulk call."],"tags":["network","http","weather-bulletin","download"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}