{"id":"be73b91ca54331ab","repo":"aio-libs/aiohttp","slug":"compress-must-be-one-of-true-false-deflate-or","errorCode":null,"errorMessage":"compress must be one of True, False, 'deflate', or 'gzip'","messagePattern":"compress must be one of True, False, 'deflate', or 'gzip'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aiohttp/client_reqrep.py","lineNumber":1215,"sourceCode":"\n        self.headers[hdrs.COOKIE] = c.output(header=\"\", sep=\";\").strip()\n\n    def _update_content_encoding(\n        self, data: Any, compress: bool | Literal[\"deflate\", \"gzip\"]\n    ) -> None:\n        \"\"\"Set request content encoding.\"\"\"\n        self.compress = None\n        if not data:\n            return\n\n        if self.headers.get(hdrs.CONTENT_ENCODING):\n            if compress:\n                raise ValueError(\n                    \"compress can not be set if Content-Encoding header is set\"\n                )\n        elif compress:\n            if isinstance(compress, str) and compress not in {\"deflate\", \"gzip\"}:\n                raise ValueError(\n                    \"compress must be one of True, False, 'deflate', or 'gzip'\"\n                )\n            self.compress = compress if isinstance(compress, str) else \"deflate\"\n            self.headers[hdrs.CONTENT_ENCODING] = self.compress\n            self.chunked = True  # enable chunked, no need to deal with length\n\n    def _update_transfer_encoding(self) -> None:\n        \"\"\"Analyze transfer-encoding header.\"\"\"\n        te = self.headers.get(hdrs.TRANSFER_ENCODING, \"\").lower()\n\n        if \"chunked\" in te:\n            if self.chunked:\n                raise ValueError(\n                    \"chunked can not be set \"\n                    'if \"Transfer-Encoding: chunked\" header is set'\n                )\n\n        elif self.chunked:","sourceCodeStart":1197,"sourceCodeEnd":1233,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/client_reqrep.py#L1197-L1233","documentation":"Raised as ValueError in ClientRequest._update_content_encoding() when `compress` is a string but not one of the two supported compression algorithms. aiohttp accepts True (defaults to deflate), False/None, or the literal strings 'deflate' and 'gzip'; anything else is rejected.","triggerScenarios":"Fires at line 1214-1217 when compress is a string not in {'deflate','gzip'}. Triggered by compress='br' (brotli), compress='zstd', compress='gzip ' (trailing space), or typos like compress='zip'.","commonSituations":"Assuming aiohttp supports the same encodings as the Accept-Encoding list (brotli/zstd); trailing whitespace; case mismatches ('GZIP' uppercase may slip through depending on version but is not guaranteed).","solutions":["Use one of the two supported lowercase strings: 'gzip' or 'deflate'.","Use True to get the default (deflate).","For brotli/zstd on the request side, pre-encode the body manually and set Content-Encoding yourself (see error 72).","Strip and lowercase dynamic compress values before passing."],"exampleFix":"# before\nawait session.post(url, data=body, compress='br')\n# after\nawait session.post(url, data=body, compress='gzip')\n# or pre-encode for unsupported algorithms\nencoded = brotli.compress(body)\nawait session.post(url, data=encoded,\n                  headers={'Content-Encoding': 'br'})","handlingStrategy":"validation","validationCode":"if isinstance(compress, str) and compress not in {'deflate', 'gzip'}:\n    raise ValueError(f\"unsupported compress {compress!r}; use 'gzip' or 'deflate'\")","typeGuard":"def is_valid_compress(c) -> bool:\n    return c in (True, False, None) or c in {'deflate', 'gzip'}","tryCatchPattern":null,"preventionTips":["Restrict compress to the supported set.","Lowercase and strip dynamic values.","For brotli/zstd, pre-encode the body and set Content-Encoding manually."],"tags":["http","compression","validation","request-building"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}