{"id":"0f0289b48a47cfb6","repo":"aio-libs/aiohttp","slug":"extension-for-deflate-not-supported-ext","errorCode":null,"errorMessage":"Extension for deflate not supported{ext}","messagePattern":"Extension for deflate not supported(.+?)","errorType":"exception","errorClass":"WSHandshakeError","httpStatus":null,"severity":"error","filePath":"aiohttp/_websocket/helpers.py","lineNumber":124,"sourceCode":"                    notakeover = True\n                # Ignore regex group 5 & 6 for client_max_window_bits\n                break\n            else:\n                if match.group(6):\n                    compress = int(match.group(6))\n                    # Group5 must match if group6 matches\n                    # Compress wbit 8 does not support in zlib\n                    # If compress level not support,\n                    # FAIL the parse progress\n                    if compress > 15 or compress < 9:\n                        raise WSHandshakeError(\"Invalid window size\")\n                if match.group(2):\n                    notakeover = True\n                # Ignore regex group 5 & 6 for client_max_window_bits\n                break\n        # Return Fail if client side and not match\n        elif not isserver:\n            raise WSHandshakeError(\"Extension for deflate not supported\" + ext.group(1))\n\n    return compress, notakeover\n\n\ndef ws_ext_gen(\n    compress: int = 15, isserver: bool = False, server_notakeover: bool = False\n) -> str:\n    # client_notakeover=False not used for server\n    # compress wbit 8 does not support in zlib\n    if compress < 9 or compress > 15:\n        raise ValueError(\n            \"Compress wbits must between 9 and 15, zlib does not support wbits=8\"\n        )\n    enabledext = [\"permessage-deflate\"]\n    if not isserver:\n        enabledext.append(\"client_max_window_bits\")\n\n    if compress < 15:","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/_websocket/helpers.py#L106-L142","documentation":"WSHandshakeError raised by ws_ext_parse() on the CLIENT side when the server's Sec-WebSocket-Extensions response contains a permessage-deflate entry whose parameters do not match the expected grammar in _WS_EXT_RE. aiohttp only understands server_no_context_takeover, client_no_context_takeover, server_max_window_bits and client_max_window_bits; anything else is treated as an unsupported extension and fails the handshake.","triggerScenarios":"The server returns 'Sec-WebSocket-Extensions: permessage-deflate; foo=bar' (or any unrecognized/ill-formed parameter suffix). The regex _WS_EXT_RE.match(defext) returns None, the code reaches the 'elif not isserver' branch, and raises with the offending suffix appended.","commonSituations":"A server or reverse proxy injects a non-standard deflate parameter; an intermediary (nginx with a custom module, a WAF) rewrites the extension header; interoperating with a library that uses experimental deflate extensions aiohttp does not implement.","solutions":["Disable compression on the client to avoid parsing the extension: await session.ws_connect(url, compress=0).","Catch WSHandshakeError around ws_connect and retry without compression.","Inspect the server's raw Sec-WebSocket-Extensions header and remove/reconfigure the offending parameter on the server side.","If you control the server, only emit the four RFC-7692 parameters aiohttp understands."],"exampleFix":"# before\nws = await session.ws_connect(url)  # WSHandshakeError: Extension for deflate not supported; foo=bar\n\n# after\nws = await session.ws_connect(url, compress=0)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from aiohttp import WSHandshakeError\n\ntry:\n    ws = await session.ws_connect(url)\nexcept WSHandshakeError as exc:\n    # server sent an unsupported deflate extension param; go uncompressed\n    ws = await session.ws_connect(url, compress=0)","preventionTips":["Treat WSHandshakeError as recoverable and fall back to compress=0.","Inspect the offending extension string in the exception message (it is appended after 'Extension for deflate not supported').","If you control the server, only emit the four RFC-7692 parameters aiohttp understands."],"tags":["websocket","handshake","compression","client","deflate"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}