{"record":{"id":"7075b7012f1e7f58","repo":"xtekky/gpt4free","slug":"failed-to-parse-message-chunk-decode-errors-rep","errorCode":null,"errorMessage":"Failed to parse message: {chunk.decode(errors='replace')}","messagePattern":"Failed to parse message: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/hf_space/BlackForestLabs_Flux1Dev.py","lineNumber":175,"sourceCode":"                                        json_data[\"output\"][\"error\"] = json_data[\n                                            \"output\"\n                                        ][\"error\"].split(\" <a \")[0]\n                                        raise ResponseError(\n                                            json_data[\"output\"][\"error\"]\n                                        )\n                                    if (\n                                        \"output\" in json_data\n                                        and \"data\" in json_data[\"output\"]\n                                    ):\n                                        yield Reasoning(status=\"\")\n                                        if len(json_data[\"output\"][\"data\"]) > 0:\n                                            yield ImageResponse(\n                                                json_data[\"output\"][\"data\"][0][\"url\"],\n                                                prompt,\n                                            )\n                                    break\n                            except (json.JSONDecodeError, KeyError, TypeError) as e:\n                                raise RuntimeError(\n                                    f\"Failed to parse message: {chunk.decode(errors='replace')}\",\n                                    e,\n                                )\n","sourceCodeStart":157,"sourceCodeEnd":179,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/hf_space/BlackForestLabs_Flux1Dev.py#L157-L179","documentation":"Raised while streaming the Gradio SSE feed of the black-forest-labs/FLUX.1-dev HF Space: a 'data: ' line's payload failed json.loads, or the parsed object lacked an expected key (output/data/progress structure). The except clause catches json.JSONDecodeError, KeyError, and TypeError from the whole processing block, and re-raises with the raw chunk text so you can see exactly what the Space sent.","triggerScenarios":"The Gradio queue sends an unexpected message type whose shape lacks keys the code indexes (e.g. progress_data entries without desc/index/length); the Space returns an HTML error page or plain-text error inside the SSE stream (JSON decode fails); the Space's Gradio version changed its queue/join queue/data protocol; or a 'process_completed' event arrives with an empty output.data list shape the code does not expect.","commonSituations":"HF Space upgraded to a newer Gradio version changing event payloads; the Space being paused/rebuilding and serving an error page on the SSE endpoint; ZeroGPU quota errors surfacing as non-JSON data frames; transient Space restarts mid-stream.","solutions":["Look at the chunk text in the message — if it is HTML or an error string, the Space itself is down/paused; retry later or pin a working Space snapshot.","If the chunk is valid JSON with a new shape, the parser needs updating for the new Gradio event format in BlackForestLabs_Flux1Dev.create_async_generator.","Pass a valid api_key/zerogpu token (or cookies) so the Space does not emit auth-error frames into the data stream.","Retry the request — Space cold starts and restarts often produce one-off malformed streams."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"def is_valid_gradio_data(chunk: bytes) -> bool:\n    return chunk.startswith(b'data: ') and chunk[6:].strip().startswith((b'{', b'['))","typeGuard":null,"tryCatchPattern":"try:\n    async for r in BlackForestLabs_Flux1Dev.create_async_generator(model=model, messages=messages, prompt=p):\n        ...\nexcept RuntimeError as e:\n    if 'Failed to parse message' in str(e):\n        # Space sent an unexpected frame: safe to retry once, then give up\n        ...","preventionTips":["Prefer raise_for_status-visible HTTP errors over stream parsing by validating the event_id assert path.","Pin to known-good HF Space revisions when possible.","Retry image requests once — Gradio streams are occasionally malformed during Space cold start."],"tags":["hf-space","gradio","sse","json","image-generation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}