{"record":{"id":"ed9fdca315e7fabc","repo":"xtekky/gpt4free","slug":"install-aiohttp-socks-package-for-proxy-support","errorCode":null,"errorMessage":"Install \"aiohttp_socks\" package for proxy support","messagePattern":"Install \"aiohttp_socks\" package for proxy support","errorType":"exception","errorClass":"MissingRequirementsError","httpStatus":null,"severity":"error","filePath":"g4f/requests/aiohttp.py","lineNumber":95,"sourceCode":"        return self.inner\n\n    async def __aexit__(self, *args, **kwargs) -> None:\n        await self.inner.close()\n\n\ndef get_connector(\n    connector: BaseConnector = None, proxy: str = None, rdns: bool = False\n) -> Optional[BaseConnector]:\n    if proxy and not connector:\n        try:\n            from aiohttp_socks import ProxyConnector\n\n            if proxy.startswith(\"socks5h://\"):\n                proxy = proxy.replace(\"socks5h://\", \"socks5://\")\n                rdns = True\n            connector = ProxyConnector.from_url(proxy, rdns=rdns)\n        except ImportError:\n            raise MissingRequirementsError(\n                'Install \"aiohttp_socks\" package for proxy support'\n            )\n    return connector\n","sourceCodeStart":77,"sourceCodeEnd":99,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/requests/aiohttp.py#L77-L99","documentation":"Raised by get_connector() in g4f/requests/aiohttp.py when a proxy URL is supplied, no custom connector was passed, and `from aiohttp_socks import ProxyConnector` fails. The aiohttp backend itself has no SOCKS support — it is delegated to aiohttp_socks — so routing an aiohttp StreamSession through a SOCKS proxy without that package raises MissingRequirementsError.","triggerScenarios":"Creating a StreamSession (aiohttp fallback backend) with proxy=\"socks5://...\" while aiohttp_socks is not installed. Also applies to http:// proxies in this code path because the connector is requested for any proxy when none was provided. Does not occur when curl_cffi is installed and used as the backend.","commonSituations":"Running g4f with only aiohttp installed (curl_cffi missing or failed to import) and setting G4F proxy environment/config; a Docker image that includes aiohttp but not aiohttp_socks; switching backends by uninstalling curl_cffi and forgetting the proxy extra.","solutions":["pip install -U aiohttp_socks (exact command in the message).","Verify import: python -c \"import aiohttp_socks\".","Alternatively install curl_cffi so the curl-based backend handles proxies natively without aiohttp_socks.","Or stop passing a proxy if direct connections are acceptable."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def can_use_proxy() -> bool:\n    try:\n        import aiohttp_socks  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nif PROXY and not can_use_proxy():\n    raise SystemExit('pip install -U aiohttp_socks')","typeGuard":null,"tryCatchPattern":"from g4f.errors import MissingRequirementsError\n\ntry:\n    session = StreamSession(proxy=PROXY)\nexcept MissingRequirementsError as e:\n    print(e)  # or continue without proxy: StreamSession()","preventionTips":["Add aiohttp_socks to requirements whenever PROXY settings may be set.","Feature-detect aiohttp_socks before constructing proxied sessions.","Prefer installing curl_cffi if you need proxies across all backends."],"tags":["proxy","socks","missing-dependency","aiohttp","aiohttp-socks"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}