{"id":"7d0cbb8d13fd92f5","repo":"psf/requests","slug":"missing-dependencies-for-socks-support","errorCode":null,"errorMessage":"Missing dependencies for SOCKS support.","messagePattern":"Missing dependencies for SOCKS support\\.","errorType":"exception","errorClass":"InvalidSchema","httpStatus":null,"severity":"error","filePath":"src/requests/adapters.py","lineNumber":67,"sourceCode":"    SSLError,\n)\nfrom .models import Response\nfrom .structures import CaseInsensitiveDict\nfrom .utils import (\n    DEFAULT_CA_BUNDLE_PATH,\n    get_auth_from_url,\n    get_encoding_from_headers,\n    prepend_scheme_if_needed,\n    select_proxy,\n    urldefragauth,\n)\n\ntry:\n    from urllib3.contrib.socks import SOCKSProxyManager  # type: ignore[assignment]\nexcept ImportError:\n\n    def SOCKSProxyManager(*args: Any, **kwargs: Any) -> None:\n        raise InvalidSchema(\"Missing dependencies for SOCKS support.\")\n\n\nif typing.TYPE_CHECKING:\n    from urllib3.connectionpool import HTTPConnectionPool\n    from urllib3.poolmanager import PoolManager as _PoolManager\n\n    from . import _types as _t\n    from .models import PreparedRequest\n\nfrom ._types import is_prepared as _is_prepared\n\nDEFAULT_POOLBLOCK = False\nDEFAULT_POOLSIZE = 10\nDEFAULT_RETRIES = 0\nDEFAULT_POOL_TIMEOUT = None\n\n\ndef _urllib3_request_context(","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/psf/requests/blob/414f0513c33883adf6f2b46901d4f0b38a455851/src/requests/adapters.py#L49-L85","documentation":"requests raises InvalidSchema('Missing dependencies for SOCKS support.') when a request is routed through a socks:// proxy but urllib3's SOCKS extras are not installed. At import time adapters.py tries `from urllib3.contrib.socks import SOCKSProxyManager`; on ImportError it substitutes a stub function that raises this error the moment a SOCKS proxy manager is actually needed. This makes SOCKS an optional feature that fails lazily rather than at import.","triggerScenarios":"Calling requests.get/post with proxies={'https': 'socks5://host:port'} (or socks4/socks5h schemes), or having ALL_PROXY/HTTPS_PROXY env vars set to a socks:// URL, in an environment where PySocks/urllib3[socks] is not installed. The stub SOCKSProxyManager at src/requests/adapters.py:66 raises when HTTPAdapter.proxy_manager_for resolves a socks-scheme proxy.","commonSituations":"Fresh virtualenvs or Docker images where `requests` was installed without the `[socks]` extra; a system-wide ALL_PROXY=socks5://... environment variable (common with shadowsocks/ssh -D setups) silently affecting scripts; CI environments that differ from a dev machine where PySocks happened to be present.","solutions":["Install the SOCKS extra: pip install 'requests[socks]' (or pip install PySocks / 'urllib3[socks]')","If you didn't intend to use a SOCKS proxy, unset ALL_PROXY/HTTP_PROXY/HTTPS_PROXY env vars pointing at socks:// URLs, or pass proxies={} / session.trust_env=False","For DNS resolution through the proxy, use the socks5h:// scheme after installing the extra"],"exampleFix":"# before\n# pip install requests\nrequests.get(url, proxies={'https': 'socks5://127.0.0.1:1080'})  # InvalidSchema\n\n# after\n# pip install 'requests[socks]'\nrequests.get(url, proxies={'https': 'socks5h://127.0.0.1:1080'})","handlingStrategy":"try-catch","validationCode":"import importlib.util\nhas_socks = importlib.util.find_spec(\"socks\") is not None\nif not has_socks:\n    raise RuntimeError(\"Install requests[socks] before using a socks:// proxy\")","typeGuard":null,"tryCatchPattern":"try:\n    resp = session.get(url, proxies={\"https\": \"socks5://host:1080\"})\nexcept ImportError as e:\n    # 'Missing dependencies for SOCKS support.'\n    raise RuntimeError(\"SOCKS proxy configured but PySocks not installed; pip install 'requests[socks]'\") from e","preventionTips":["Declare requests[socks] (not bare requests) in requirements when any proxy URL may use a socks:// scheme","Fail fast at startup by probing importlib.util.find_spec('socks') when config contains a SOCKS proxy","Cover proxy configuration paths in CI with the real extra installed"],"tags":["network","proxy","socks","dependencies","python"],"analyzedSha":"414f0513c33883adf6f2b46901d4f0b38a455851","analyzedAt":"2026-07-31T19:24:57.696Z","schemaVersion":2}