{"record":{"id":"976d8bb5e52b4d45","repo":"xtekky/gpt4free","slug":"polling-images-faild-code-response-status","errorCode":null,"errorMessage":"Polling images faild. Code: {response.status}","messagePattern":"Polling images faild\\. Code: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/bing/create_images.py","lineNumber":127,"sourceCode":"            if response.status != 302:\n                raise RuntimeError(f\"Create images failed. Code: {response.status}\")\n\n    redirect_url = response.headers[\"Location\"].replace(\"&nfy=1\", \"\")\n    redirect_url = f\"{BING_URL}{redirect_url}\"\n    request_id = redirect_url.split(\"id=\")[-1]\n    async with session.get(redirect_url) as response:\n        response.raise_for_status()\n\n    polling_url = (\n        f\"{BING_URL}/images/create/async/results/{request_id}?q={url_encoded_prompt}\"\n    )\n    start_time = time.time()\n    while True:\n        if time.time() - start_time > timeout:\n            raise RuntimeError(f\"Timeout error after {timeout} sec\")\n        async with session.get(polling_url) as response:\n            if response.status != 200:\n                raise RuntimeError(f\"Polling images faild. Code: {response.status}\")\n            text = await response.text()\n            if not text or \"GenerativeImagesStatusPage\" in text:\n                await asyncio.sleep(1)\n            else:\n                break\n    error = None\n    try:\n        error = json.loads(text).get(\"errorMessage\")\n    except Exception:\n        pass\n    if error == \"Pending\":\n        raise RuntimeError(\"Prompt is been blocked\")\n    elif error:\n        raise RuntimeError(error)\n    return read_images(text)\n\n\ndef read_images(html_content: str) -> List[str]:","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/bing/create_images.py#L109-L145","documentation":"Raised as RuntimeError by Bing image creation when a poll of the async-results URL returns a non-200 status. Each poll iteration expects HTTP 200 (body may still be 'pending'); any other status means the polling request itself failed and the loop aborts with that code.","triggerScenarios":"The results endpoint returns 4xx/5xx during polling: expired request id, auth cookies dropped mid-flow, or server-side error serving results.","commonSituations":"Polling continued too long so the request id expired, cookie session invalidated between submission and polling, transient 5xx on Bing's results endpoint.","solutions":["Retry the whole create_images call for transient 5xx polls","Refresh Bing cookies if the status suggests auth failure (401/403)","Reduce timeout/latency between submission and polling so the request id stays valid"],"exampleFix":"# before\nimages = create_images(session, prompt, cookies)\n# RuntimeError: Polling images faild. Code: 500\n\n# after\nfor attempt in range(3):\n    try:\n        images = create_images(session, prompt, cookies)\n        break\n    except RuntimeError as e:\n        if 'Polling images faild' not in str(e) or attempt == 2:\n            raise\n        time.sleep(5)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        images = create_images(session, prompt, cookies)\n        break\n    except RuntimeError as e:\n        if 'Polling images faild' not in str(e) or attempt == 2:\n            raise\n        time.sleep(5)","preventionTips":["Retry the full flow on transient poll failures rather than failing the user request","Refresh cookies if polling returns 401/403 — the session dropped mid-flow"],"tags":["polling","http","retry","bing","image-generation","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}