{"id":"c81193fbab12af47","repo":"aio-libs/aiohttp","slug":"resolver-requires-aiodns-library","errorCode":null,"errorMessage":"Resolver requires aiodns library","messagePattern":"Resolver requires aiodns library","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"aiohttp/resolver.py","lineNumber":107,"sourceCode":"                    port=port,\n                    family=family,\n                    proto=proto,\n                    flags=_NUMERIC_SOCKET_FLAGS,\n                )\n            )\n\n        return hosts\n\n    async def close(self) -> None:\n        pass\n\n\nclass AsyncResolver(AbstractResolver):\n    \"\"\"Use the `aiodns` package to make asynchronous DNS lookups\"\"\"\n\n    def __init__(self, *args: Any, **kwargs: Any) -> None:\n        if aiodns is None:\n            raise RuntimeError(\"Resolver requires aiodns library\")\n\n        self._loop = asyncio.get_running_loop()\n        self._manager: _DNSResolverManager | None = None\n        # If custom args are provided, create a dedicated resolver instance\n        # This means each AsyncResolver with custom args gets its own\n        # aiodns.DNSResolver instance\n        if args or kwargs:\n            self._resolver = aiodns.DNSResolver(*args, **kwargs)\n            return\n        # Use the shared resolver from the manager for default arguments\n        self._manager = _DNSResolverManager()\n        self._resolver = self._manager.get_resolver(self, self._loop)\n\n    async def resolve(\n        self, host: str, port: int = 0, family: socket.AddressFamily = socket.AF_INET\n    ) -> list[ResolveResult]:\n        try:\n            try:","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/resolver.py#L89-L125","documentation":"Raised by AsyncResolver.__init__ when the aiodns package is not importable. aiohttp resolvers are pluggable; AsyncResolver delegates to aiodns for true non-blocking DNS. If aiodns is missing, construction aborts with RuntimeError so the failure is loud rather than silently falling back to the threaded resolver. Install aiodns or use the default ThreadedResolver.","triggerScenarios":"Instantiating aiohttp.resolver.AsyncResolver() (explicitly, or via connector=TCPConnector(resolver=AsyncResolver())) without aiodns installed. Also triggered if aiodns is installed but its import fails due to a broken cffi/pycares build.","commonSituations":"Deploying to a slim container or Alpine image that omits aiodns; pinning requirements without aiodns; upgrading Python in a way that breaks aiodns' cffi wheels; using AsyncResolver as DefaultResolver when aiodns was optional.","solutions":["Install aiodns: `pip install aiodns` (on Alpine also `apk add libcares`/build deps for cffi).","If you do not need async DNS, do not pass AsyncResolver — rely on the default (ThreadedResolver when aiodns is absent).","Pin aiodns>=3.0 for modern Python versions and ensure wheels exist for your platform.","Verify with `python -c 'import aiodns'` after install."],"exampleFix":"// before\nfrom aiohttp.resolver import AsyncResolver\nconnector = TCPConnector(resolver=AsyncResolver())\n// after\n# Option A: install dependency\n#   pip install aiodns\n# Option B: use default resolver\nconnector = TCPConnector()  # ThreadedResolver by default","handlingStrategy":"validation","validationCode":"try:\n    import aiodns  # noqa\n    HAS_AIODNS = True\nexcept ImportError:\n    HAS_AIODNS = False\n\nfrom aiohttp.resolver import AsyncResolver, ThreadedResolver\n\nresolver = AsyncResolver() if HAS_AIODNS else ThreadedResolver()","typeGuard":null,"tryCatchPattern":"try:\n    resolver = AsyncResolver()\nexcept RuntimeError:\n    # aiodns missing — fall back\n    resolver = ThreadedResolver()","preventionTips":["Pin aiodns in requirements when you opt into AsyncResolver.","Add `python -c 'import aiodns'` to your container's health check.","Document the optional dependency in the deploy README."],"tags":["dns","dependency","configuration"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}