{"record":{"id":"539c080c26970888","repo":"unclecode/crawl4ai","slug":"connection-failed-str-e","errorCode":null,"errorMessage":"Connection failed: {str(e)}","messagePattern":"Connection failed: (.+?)","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"crawl4ai/async_crawler_strategy.py","lineNumber":2784,"sourceCode":"\n                    result = AsyncCrawlResponse(\n                        html=html,\n                        response_headers=response_headers,\n                        status_code=response.status,\n                        redirected_url=str(response.url),\n                        downloaded_files=downloaded_files,\n                    )\n\n                    await self.hooks['after_request'](result)\n                    return result\n\n            except aiohttp.ServerTimeoutError as e:\n                await self.hooks['on_error'](e)\n                raise ConnectionTimeoutError(f\"Request timed out: {str(e)}\")\n                \n            except aiohttp.ClientConnectorError as e:\n                await self.hooks['on_error'](e)\n                raise ConnectionError(f\"Connection failed: {str(e)}\")\n                \n            except aiohttp.ClientError as e:\n                await self.hooks['on_error'](e)\n                raise HTTPCrawlerError(f\"HTTP client error: {str(e)}\")\n            \n            except asyncio.exceptions.TimeoutError as e:\n                await self.hooks['on_error'](e)\n                raise ConnectionTimeoutError(f\"Request timed out: {str(e)}\")\n            \n            except Exception as e:\n                await self.hooks['on_error'](e)\n                raise HTTPCrawlerError(f\"HTTP request failed: {str(e)}\")\n\n    async def crawl(\n        self, \n        url: str, \n        config: Optional[CrawlerRunConfig] = None, \n        **kwargs","sourceCodeStart":2766,"sourceCodeEnd":2802,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/async_crawler_strategy.py#L2766-L2802","documentation":"Raised when aiohttp raises ClientConnectorError, meaning the TCP/TLS connection could never be established: DNS resolution failure, refused connection, unreachable host, or TLS handshake failure. The HTTP crawler wraps it into a plain ConnectionError with the underlying cause text.","triggerScenarios":"Crawling a URL whose host does not resolve (typo, dead domain); target port not listening (dev server down); firewall/proxy blocking egress; TLS certificate rejected at handshake; IPv6-only host without IPv6 connectivity.","commonSituations":"Crawling localhost during local development when the dev server is not running; CI environments without network access or with DNS restrictions; expired domains in stale URL lists; corporate proxies requiring explicit configuration.","solutions":["Fix or verify the URL/host and check DNS (dig/nslookup) from the same environment.","For local targets, confirm the dev server is up and the port matches.","Configure proxy settings if the environment requires an egress proxy.","Catch ConnectionError per URL during batch crawls and mark the URL dead rather than aborting the run."],"exampleFix":"// before\nresults = [await crawler.arun(u) for u in urls]  # one dead host kills the batch\n\n// after\nresults = []\nfor u in urls:\n    try:\n        results.append(await crawler.arun(u))\n    except ConnectionError as e:\n        logger.warning(f\"unreachable, skipping {u}: {e}\")","handlingStrategy":"try-catch","validationCode":"import socket\nfrom urllib.parse import urlparse\n\ndef host_resolves(url: str) -> bool:\n    host = urlparse(url).hostname\n    if not host:\n        return False\n    try:\n        socket.gethostbyname(host)\n        return True\n    except socket.gaierror:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    result = await crawler.arun(url)\nexcept ConnectionError as e:\n    if \"Connection failed\" in str(e):\n        mark_unreachable(url)","preventionTips":["Verify dev servers are running before crawling localhost","Check DNS/proxy egress in CI","Filter dead domains from crawl lists early"],"tags":["connection","dns","http-crawler","network"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}