{"id":"d3ad72dead8be317","repo":"aio-libs/aiohttp","slug":"unknown-content-transfer-encoding-encoding","errorCode":null,"errorMessage":"unknown content transfer encoding: {encoding}","messagePattern":"unknown content transfer encoding: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"aiohttp/multipart.py","lineNumber":607,"sourceCode":"                suppress_deflate_header=True,\n            )\n            yield await d.decompress(data, max_length=self._max_decompress_size)\n            while d.data_available:\n                yield await d.decompress(b\"\", max_length=self._max_decompress_size)\n        else:\n            raise RuntimeError(f\"unknown content encoding: {encoding}\")\n\n    def _decode_content_transfer(self, data: bytes) -> bytes:\n        encoding = self.headers.get(CONTENT_TRANSFER_ENCODING, \"\").lower()\n\n        if encoding == \"base64\":\n            return base64.b64decode(data)\n        elif encoding == \"quoted-printable\":\n            return binascii.a2b_qp(data)\n        elif encoding in (\"binary\", \"8bit\", \"7bit\"):\n            return data\n        else:\n            raise RuntimeError(f\"unknown content transfer encoding: {encoding}\")\n\n    def get_charset(self, default: str) -> str:\n        \"\"\"Returns charset parameter from Content-Type header or default.\"\"\"\n        ctype = self.headers.get(CONTENT_TYPE, \"\")\n        mimetype = parse_mimetype(ctype)\n        return mimetype.parameters.get(\"charset\", self._default_charset or default)\n\n    @reify\n    def name(self) -> str | None:\n        \"\"\"Returns name specified in Content-Disposition header.\n\n        If the header is missing or malformed, returns None.\n        \"\"\"\n        _, params = parse_content_disposition(self.headers.get(CONTENT_DISPOSITION))\n        return content_disposition_filename(params, \"name\")\n\n    @reify\n    def filename(self) -> str | None:","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/multipart.py#L589-L625","documentation":"Raised by BodyPartReader._decode_content_transfer when a part's Content-Transfer-Encoding header is not one of the recognized values (base64, quoted-printable, binary, 8bit, 7bit). This method runs whenever a part has a Content-Transfer-Encoding header and the bytes need to be decoded.","triggerScenarios":"A received multipart part carries a Content-Transfer-Encoding header with an unrecognized token (e.g. 'uuencode', 'x-gzip', 'base-64' typo, or any custom value). Surfaced during `await part.read(decode=True)` / `part.decode(data)` because _apply_content_transfer_decoding is always applied when the header is present.","commonSituations":"Mail-style MIME parts forwarded into HTTP; legacy clients sending non-standard transfer encodings; typo in the header value; a gateway adding an encoding aiohttp does not implement.","solutions":["Correct or remove the Content-Transfer-Encoding header on the sender so it is one of base64/quoted-printable/binary/8bit/7bit.","If you must handle a custom encoding, read raw bytes with `await part.read(decode=False)` (note: this still calls transfer decoding — delete the header from part.headers first), then decode manually.","Pre-validate part.headers before consuming the part."],"exampleFix":"// before\ndata = await part.read(decode=True)  # Content-Transfer-Encoding: uuencode\n// after\ndel part.headers['Content-Transfer-Encoding']\nraw = await part.read(decode=False)\ndata = uu_decode(raw)\n","handlingStrategy":"validation","validationCode":"cte = part.headers.get('Content-Transfer-Encoding', '').lower()\nif cte and cte not in ('base64', 'quoted-printable', 'binary', '8bit', '7bit'):\n    raise UnsupportedEncoding(f'unsupported CTE: {cte}')","typeGuard":"def is_supported_cte(part) -> bool:\n    cte = part.headers.get('Content-Transfer-Encoding', '').lower()\n    return cte in ('', 'base64', 'quoted-printable', 'binary', '8bit', '7bit')","tryCatchPattern":"try:\n    data = await part.read(decode=True)\nexcept RuntimeError as e:\n    if 'unknown content transfer encoding' in str(e):\n        del part.headers['Content-Transfer-Encoding']\n        data = await part.read(decode=False)\n    else:\n        raise","preventionTips":["Whitelist Content-Transfer-Encoding values at ingestion.","Reject MIME-only encodings (uuencode, x-*) before they reach the reader.","For form-data, CTE should be absent entirely."],"tags":["multipart","content-transfer-encoding","mime","decoding"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}