{"record":{"id":"97fc26728e73c2a3","repo":"aio-libs/aiohttp","slug":"clienthttpproxyerror-message","errorCode":null,"errorMessage":"ClientHttpProxyError: {message}","messagePattern":"ClientHttpProxyError: (.+?)","errorType":"exception","errorClass":"ClientHttpProxyError","httpStatus":null,"severity":"error","filePath":"aiohttp/connector.py","lineNumber":1641,"sourceCode":"                # once the response is received and processed allowing\n                # START_TLS to work on the connection below.\n                protocol.set_response_params(\n                    read_until_eof=True,\n                    timeout_ceil_threshold=self._timeout_ceil_threshold,\n                )\n                resp = await proxy_resp.start(conn)\n            except BaseException:\n                proxy_resp.close()\n                conn.close()\n                raise\n            else:\n                conn._protocol = None\n                try:\n                    if resp.status != 200:\n                        message = resp.reason\n                        if message is None:\n                            message = HTTPStatus(resp.status).phrase\n                        raise ClientHttpProxyError(\n                            proxy_resp.request_info,\n                            resp.history,\n                            status=resp.status,\n                            message=message,\n                            headers=resp.headers,\n                        )\n                except BaseException:\n                    # It shouldn't be closed in `finally` because it's fed to\n                    # `loop.start_tls()` and the docs say not to touch it after\n                    # passing there.\n                    transport.close()\n                    raise\n\n                return await self._start_tls_connection(\n                    # Access the old transport for the last time before it's\n                    # closed and forgotten forever:\n                    transport,\n                    req=req,","sourceCodeStart":1623,"sourceCodeEnd":1659,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/d041d4d0fd48c3f0832084d33be16cf1c4835f85/aiohttp/connector.py#L1623-L1659","documentation":"Raised inside _create_proxy_connection when the proxy's response to the CONNECT request has a status other than 200. aiohttp had successfully established a transport to the proxy and issued CONNECT host:port, but the proxy refused to tunnel (401/403/407/502/etc.). The proxy's reason phrase (or the HTTPStatus phrase if reason is missing) is carried as the message, so the failure cause from the proxy is visible.","triggerScenarios":"Proxy requires authentication that was not supplied (407 Proxy Authentication Required); proxy denied by ACL (403); proxy could not reach the upstream (502/504); wrong proxy URL; proxy requires credentials in a different scheme (Basic vs Digest); expired proxy credentials.","commonSituations":"Corporate proxy credentials rotated; environment HTTP_PROXY/HTTPS_PROXY pointing at the wrong proxy; proxy auth header not set because aiohttp's proxy auth was not configured; proxy blocking the target host by policy.","solutions":["Supply proxy credentials via the proxy URL (http://user:pass@proxy:port) or proxy_headers Authorization/Proxy-Authorization.","Verify the proxy allows CONNECT to the target host and port (proxy ACL).","Check HTTP_PROXY/HTTPS_PROXY/NO_PROXY env vars for stale or mistyped values.","Reproduce with curl -x http://proxy:port https://target to confirm the proxy, not aiohttp, is rejecting."],"exampleFix":"# before\nawait session.get('https://target/', proxy='http://corp-proxy:8080')\n# after - add proxy auth\nfrom urllib.parse import quote\nproxy = 'http://{}:{}@corp-proxy:8080'.format(quote(user), quote(password))\nawait session.get('https://target/', proxy=proxy)","handlingStrategy":"try-catch","validationCode":"from urllib.parse import urlparse, quote\n\ndef proxy_with_auth(proxy_url, user, password):\n    p = urlparse(proxy_url)\n    userinfo = f'{quote(user, safe=\"\")}:{quote(password, safe=\"\")}@'\n    return f'{p.scheme}://{userinfo}{p.hostname}:{p.port}'\n\nproxy = proxy_with_auth(base_proxy, user, password)","typeGuard":"null","tryCatchPattern":"try:\n    resp = await session.get(url, proxy=proxy)\nexcept aiohttp.ClientHttpProxyError as exc:\n    if exc.status in (401, 407):\n        proxy = refresh_proxy_credentials()\n        resp = await session.get(url, proxy=proxy)\n    else:\n        raise","preventionTips":["Supply proxy credentials in the proxy URL or via proxy_headers.","Verify the proxy permits CONNECT to the target host and port.","Reproduce proxy rejection with curl -x to confirm the proxy, not aiohttp, is denying."],"tags":["proxy","connection","authentication","client-connector"],"backgroundTag":null,"analyzedSha":"d041d4d0fd48c3f0832084d33be16cf1c4835f85","analyzedAt":"2026-08-11T20:44:15.550Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}