xtekky/gpt4free · error · MissingRequirementsError

Install "aiohttp_socks" package for proxy support

Error message

Install "aiohttp_socks" package for proxy support

What it means

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.

Source

Thrown at g4f/requests/aiohttp.py:95

        return self.inner

    async def __aexit__(self, *args, **kwargs) -> None:
        await self.inner.close()


def get_connector(
    connector: BaseConnector = None, proxy: str = None, rdns: bool = False
) -> Optional[BaseConnector]:
    if proxy and not connector:
        try:
            from aiohttp_socks import ProxyConnector

            if proxy.startswith("socks5h://"):
                proxy = proxy.replace("socks5h://", "socks5://")
                rdns = True
            connector = ProxyConnector.from_url(proxy, rdns=rdns)
        except ImportError:
            raise MissingRequirementsError(
                'Install "aiohttp_socks" package for proxy support'
            )
    return connector

View on GitHub (pinned to 973504e177)

Solutions

  1. pip install -U aiohttp_socks (exact command in the message).
  2. Verify import: python -c "import aiohttp_socks".
  3. Alternatively install curl_cffi so the curl-based backend handles proxies natively without aiohttp_socks.
  4. Or stop passing a proxy if direct connections are acceptable.
Defensive patterns

Strategy: validation

Validate before calling

def can_use_proxy() -> bool:
    try:
        import aiohttp_socks  # noqa: F401
        return True
    except ImportError:
        return False

if PROXY and not can_use_proxy():
    raise SystemExit('pip install -U aiohttp_socks')

Try / catch

from g4f.errors import MissingRequirementsError

try:
    session = StreamSession(proxy=PROXY)
except MissingRequirementsError as e:
    print(e)  # or continue without proxy: StreamSession()

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/ed9fdca315e7fabc. Report an issue: GitHub.