{"record":{"id":"ad9b0dd0fd71740b","repo":"arduino/Arduino","slug":"received-response-with-content-encoding-s-but-f","errorCode":null,"errorMessage":"Received response with content-encoding: %s, but failed to decode it.","messagePattern":"Received response with content-encoding: (.+?), but failed to decode it\\.","errorType":"exception","errorClass":"DecodeError","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/response.py","lineNumber":164,"sourceCode":"                data = self._fp.read()\n            else:\n                data = self._fp.read(amt)\n                if amt != 0 and not data:  # Platform-specific: Buggy versions of Python.\n                    # Close the connection when no data is returned\n                    #\n                    # This is redundant to what httplib/http.client _should_\n                    # already do.  However, versions of python released before\n                    # December 15, 2012 (http://bugs.python.org/issue16298) do not\n                    # properly close the connection in all cases. There is no harm\n                    # in redundantly calling close.\n                    self._fp.close()\n                return data\n\n            try:\n                if decode_content and decoder:\n                    data = decoder(data)\n            except (IOError, zlib.error):\n                raise DecodeError(\"Received response with content-encoding: %s, but \"\n                                  \"failed to decode it.\" % content_encoding)\n\n            if cache_content:\n                self._body = data\n\n            return data\n\n        finally:\n            if self._original_response and self._original_response.isclosed():\n                self.release_conn()\n\n    @classmethod\n    def from_httplib(ResponseCls, r, **response_kw):\n        \"\"\"\n        Given an :class:`httplib.HTTPResponse` instance ``r``, return a\n        corresponding :class:`urllib3.response.HTTPResponse` object.\n\n        Remaining parameters are passed to the HTTPResponse constructor, along","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/response.py#L146-L182","documentation":"urllib3 promised a compressed response (Content-Encoding header, e.g. gzip/deflate) but the decompressor (zlib/GzipFile) raised IOError or zlib.error while decoding the body, so urllib3 wraps it in a DecodeError. The bytes on the wire are not valid data for the declared encoding.","triggerScenarios":"A server/proxy sets 'Content-Encoding: gzip' but sends uncompressed, truncated, or corrupt bytes; a double-compression bug ('Content-Encoding: gzip, gzip' with single-encoded body); streaming reads (resp.read()) that hit the malformed chunk mid-stream.","commonSituations":"Buggy middlewares/CDNs mangling bodies; responses consumed after a failed request; custom WSGI apps adding the header without compressing; resuming a truncated download; requests' automatic decode_content interacting with manual decompression.","solutions":["Inspect the raw body: request with headers={'Accept-Encoding': 'identity'} or resp.read(decode_content=False) to see the actual bytes and find who mangles them.","Fix the server/proxy to only set Content-Encoding when it actually compresses the payload.","If you decompress manually, pass decode_content=False so urllib3 does not also try to decode.","Retry the request — if it is intermittent it may be a truncated response from a proxy; add error handling around read()."],"exampleFix":"// before\nr = http.request('GET', url)\nbody = r.read()  # DecodeError: claims gzip but isn't\n// after\nr = http.request('GET', url, headers={'Accept-Encoding': 'identity'})\nbody = r.read()","handlingStrategy":"try-catch","validationCode":"ce = resp.headers.get('Content-Encoding')\nif ce and ce.strip().lower() not in ('', 'identity'):\n    # inspect raw bytes before decoding\n    raw = resp.read(decode_content=False)\n    if ce == 'gzip' and raw[:2] != b'\\x1f\\x8b':\n        raise ValueError('Server sent Content-Encoding: gzip without gzip data')","typeGuard":null,"tryCatchPattern":"from urllib3.exceptions import DecodeError\ntry:\n    body = resp.read()\nexcept DecodeError as e:\n    log.warning('Bad content-encoding from %s: %s', resp.url, e)\n    body = resp.read(decode_content=False)  # fall back to raw bytes","preventionTips":["Send Accept-Encoding only for encodings you trust the server/proxy to honor.","Check proxies/CDN/WAF configs that rewrite bodies but keep Content-Encoding.","Handle DecodeError when streaming large downloads (truncation happens mid-stream).","Test endpoints with curl --compressed to compare behavior."],"tags":["http","gzip","decoding","urllib3","network"],"backgroundTag":"invalid-json-response","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}