{"record":{"id":"7652f22323bfead8","repo":"xtekky/gpt4free","slug":"failed-to-parse-image-url-chunk-decode-errors-r","errorCode":null,"errorMessage":"Failed to parse image URL: {chunk.decode(errors='replace')}","messagePattern":"Failed to parse image URL: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/hf_space/StabilityAI_SD35Large.py","lineNumber":91,"sourceCode":"                ) as event_response:\n                    event_response.raise_for_status()\n                    event = None\n                    async for chunk in event_response.content:\n                        if chunk.startswith(b\"event: \"):\n                            event = chunk[7:].decode(errors=\"replace\").strip()\n                        if chunk.startswith(b\"data: \"):\n                            if event == \"error\":\n                                raise ResponseError(\n                                    f\"GPU token limit exceeded: {chunk.decode(errors='replace')}\"\n                                )\n                            if event in (\"complete\", \"generating\"):\n                                try:\n                                    data = json.loads(chunk[6:])\n                                    if data is None:\n                                        continue\n                                    url = data[0][\"url\"]\n                                except (json.JSONDecodeError, KeyError, TypeError) as e:\n                                    raise RuntimeError(\n                                        f\"Failed to parse image URL: {chunk.decode(errors='replace')}\",\n                                        e,\n                                    )\n                                if event == \"generating\":\n                                    yield ImagePreview(url, prompt)\n                                else:\n                                    yield ImageResponse(url, prompt)\n                                    break\n","sourceCodeStart":73,"sourceCodeEnd":100,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/hf_space/StabilityAI_SD35Large.py#L73-L100","documentation":"Raised in the StabilityAI SD3.5 Large Space stream when a 'complete' or 'generating' SSE event's data payload fails to parse as the expected shape: the code expects json.loads(chunk[6:]) to yield a list whose first element has a 'url' key (data[0]['url']). JSONDecodeError, KeyError (no 'url'), or TypeError (data is not a list / None handling aside) all land here, with the raw chunk embedded in the message.","triggerScenarios":"The Space returns a dict instead of a list (Gradio version change), an output entry without a url (e.g. an error/status object), a JSON payload split across SSE lines, or an HTML/HTML-fragment payload in the data frame; also fires if the event variable from a previous 'event:' line mismatches the data frame ordering.","commonSituations":"Gradio upgrades on the Space changing output payload shape ([{url:...}] vs {url:...}); error frames mislabeled as 'generating'; intermittent malformed frames during Space cold start.","solutions":["Inspect the chunk text in the message to see the actual payload shape; adapt the url extraction (data[0]['url']) to match.","If the payload is an error object, address the underlying Space error (often ZeroGPU quota — see the event: error path just above).","Retry — transient malformed frames during Space restarts resolve themselves.","If the shape permanently changed, update the parser in StabilityAI_SD35Large.py to the new Gradio output format."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ...\nexcept RuntimeError as e:\n    if 'Failed to parse image URL' in str(e):\n        # inspect chunk in message; transient frames justify one retry\n        ...","preventionTips":["Retry once on parse failures — Gradio frames are intermittently malformed under load.","Capture the failing chunk in logs to detect permanent shape changes early.","Keep g4f updated so Space protocol changes are handled upstream."],"tags":["hf-space","json","gradio","sse","image-generation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}